macOS:配置:错误:C编译器无法创建可执行文件

时间:2020-02-23 14:45:04  来源:igfitidea点击:

configure: error: C compiler cannot create executables

使用GCC编译器时遇到一些问题?该问题可能在不同的情况下出现,例如:

调用GCC编译器尝试使用" sudo ./configure"手动编译应用程序。
在这种情况下,将显示类似以下的输出:

checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/path/to/some/source/folder':
configure: error: C compiler cannot create executables

在使用" sudo端口升级过期"更新MacPorts(也调用GCC)之后尝试升级过期的软件包。
在这种情况下,将显示类似以下的输出:

[...]
Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: No port libedit found in the index.
Warning: No port libffi found in the index.
Warning: No port xar found in the index.
Warning: No port libcxx found in the index.
Warning: No port perl5 found in the index.
Warning: No port llvm_select found in the index.
---> Computing dependencies for some-package-0.0 Error: Problem while installing some-package-0.0
Error: Follow https://guide.macports.org/#project.tickets to report a bug.

在那种情况下,该问题发生在Xcode更新(也更新提供GCC的Xcode命令行工具)之后。
每次更新Xcode时,必须先接受GCC的许可协议,然后才能使用它。

如果类似的情况适用于您的情况,则很可能是问题所在。
您可以通过发出以下命令轻松找到:

gcc -v

如果此问题与您的情况相符,将返回以下输出:

Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.

为了阅读和接受许可证,请按照建议运行以下命令:

sudo xcodebuild -license

阅读完许可证后,只需执行"接受"。

完成后,您可以再次使用" gcc -v"命令查看GCC编译器现在是否可用,如果成功,现在将显示类似以下的输出:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin