MacOS“配置:错误:无法运行C编译程序”

Edd*_*die 8 c macos compiler-errors

我对MacOS环境还很陌生,以前在编译C脚本时遇到一些问题。我有以下问题:

fatal error: stdio.h: No such file or directory
 #include <stdio.h>
                   ^
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

我尝试重新安装,xcode-select --install但一直告诉我

xcode-select:错误:命令行工具已经安装,请使用“软件更新”来安装更新

我什么都没更新。显然是因为我没有/usr/includes文件。我找到了一种使用来编译软件的方法

/Library/Developer/CommandLineTools/usr/bin/g++ XXXX.cpp

不过,现在我想./compilemake其他软件,但我不知道如何在默认情况下使用该GCC解释。当我尝试./configure时出现此错误

配置:错误:无法运行C编译程序。如果您打算交叉编译,请使用'--host'。有关更多详细信息,请参见“ config.log”

所以当我调查config.log

configure:3224: checking for gcc
configure:3240: found /usr/local/bin/gcc
configure:3251: result: gcc
configure:3282: checking for C compiler version
configure:3291: gcc --version >&5
gcc (GCC) 4.9.2 20141029 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:3302: $? = 0
configure:3291: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../gcc-4.9-20141029/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 4.9.2 20141029 (prerelease) (GCC) 
configure:3302: $? = 0
configure:3291: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3302: $? = 1
configure:3291: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:3302: $? = 1
configure:3322: checking whether the C compiler works
configure:3344: gcc    conftest.c  >&5
configure:3348: $? = 0
configure:3396: result: yes
configure:3399: checking for C compiler default output file name
configure:3401: result: a.out
configure:3407: checking for suffix of executables
configure:3414: gcc -o conftest    conftest.c  >&5
configure:3418: $? = 0
configure:3440: result: 
configure:3462: checking whether we are cross compiling
configure:3470: gcc -o conftest    conftest.c  >&5
conftest.c:15:19: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
                   ^
compilation terminated.
configure:3474: $? = 1
configure:3481: ./conftest
./configure: line 3483: ./conftest: No such file or directory
configure:3485: $? = 127
configure:3492: error: in `/Users/XXXX/phyml':
configure:3494: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
Run Code Online (Sandbox Code Playgroud)

您对我该如何解决有任何想法?

非常感谢 !

Oli*_*can 11

在这个问题的一些小评论中,很容易会漏掉melpomene的答案,所以让我在这里发布此内容,以供所有人查看。此错误通常意味着您缺少从Xcode中删除的编译器工具(实际上是标题)。

您可以在其中找到它们,/Library/Developer/CommandLineTools/Packages/因为它们的名称可能会有所不同,具体取决于将来的macOS版本。

假设您正在运行macOS Mojave(10.14),则需要运行:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Run Code Online (Sandbox Code Playgroud)

然后,将启动macOS风格的软件包安装程序,询问您的管理员密码。这是Apple的官方软件包,尽管从随机目录中安装某些内容可能很奇怪,但是您可以信任它。不过,您不必相信我的话。Apple在Xcode 10发行说明中掩埋了此更改,您可以在这里找到其说明:https : //developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035623

如果此链接消失或更改,我将在这里重现此内容:

命令行工具程序包将macOS系统标头安装在macOS SDK中。使用已安装工具编译的软件将在以下任一位置的Xcode提供的macOS SDK中搜索标头:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

或命令行工具位于:

/图书馆/开发人员/CommandLineTools/SDKs/MacOSX.sdk

取决于使用xcode-select选择的内容。

默认情况下,命令行工具将在SDK中搜索系统标头。但是,某些软件可能无法根据SDK正确构建,并要求在/ usr / include下的基本系统中安装macOS标头。如果您是此类软件的维护者,我们建议您更新项目以使其与SDK配合使用,或者针对存在妨碍您执行此操作的问题提交错误报告。解决方法是,提供一个额外的程序包,该程序包会将标头安装到基本系统。在将来的版本中,将不再提供此软件包。您可以在以下位置找到此软件包:

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg?>为确保您使用的是命令行工具的预期版本,请运行xcode-select -s或xcode select -s / Library / Developer / CommandLineTools安装后。

  • 为什么它说 macOS_SDK_headers_for_macOS_10.14.pkg 不存在?...我使用的是 macOS 10.15.3.. (2认同)