Mojave中使用gcc进行编译

Mojave中使用gcc进行编译

本文介绍了在macOS Mojave中使用gcc进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新到Mojave之前,我正在编译C程序.我使用的是gcc 7.3的旧版本,该版本是按照此处中找到的说明安装的.

Before updating to Mojave I was compiling C programs just fine. I used an older version of gcc, 7.3, that I installed using the instructions found here.

然后我更新到Mojave并尝试编译gcc main.c之后的简单程序:

Then I updated to Mojave and tried compiling the simple program that follows with gcc main.c:

#include <stdio.h>
int main(){
    printf("Hello World\n");
    return 0;}

这将导致以下错误:

/usr/local/lib/gcc/x86_64-apple-darwin17.5.0/7.3.0/include-fixed/stdio.h:78:10: fatal error: _stdio.h: No such file or directory
 #include <_stdio.h>
      ^~~~~~~~~~
compilation terminated.

如果我删除了include,它将使用printf的隐式声明警告进行编译,但仍将编译并正常运行,并打印Hello World.有谁知道这个问题以及我该如何解决?

If I remove the include it will compile with implicit declaration warnings for printf, but will still compile and run properly, printing Hello World. Does anyone know the issue and how I can fix it?

推荐答案

我想出了解决方法.我去了

I figured out how to fix it. I went to

/Library/Developer/CommandLineTools/Packages/

然后打开并安装macOS_SDK_headers_for_macOS_10.14.pkg.

then opened and installed macOS_SDK_headers_for_macOS_10.14.pkg.

这篇关于在macOS Mojave中使用gcc进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:26