MacOS“配置:错误:无法运行C编译程序" [英] MacOS "configure: error: cannot run C compiled programs"

查看:181
本文介绍了MacOS“配置:错误:无法运行C编译程序"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am pretty new to the MacOS environment and I previously had some issue compiling C scripts. I had the following issue:

fatal error: stdio.h: No such file or directory
 #include <stdio.h>
                   ^
compilation terminated.

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

I tried to re-install xcode-select --install but keep telling me

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

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

我什么都没更新.显然是因为我没有/usr/includes文件.我找到了一种使用

I updated everything and nothing. Apparently it is because I don't have the /usr/includes file. I found a way to compile my software by using

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

但是,现在我正在尝试./compilemake另一个软件,但是我不知道默认情况下如何使用此gcc解释器.当我尝试./configure时出现此错误

However, now I am trying to ./compile and make another software but I don't know how to use this gcc interpreter by default. When I try to ./configure I got this error

配置:错误:无法运行C编译程序.如果你想 交叉编译,请使用"--host".有关更多详细信息,请参见"config.log"

configure: error: cannot run C compiled programs. If you meant to cross compile, use '--host'. See 'config.log' for more details

所以当我查看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

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

Do you have any ideas of how I can fix it ?

非常感谢!

推荐答案

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

It's really easy to miss the answer from melpomene in the small comments to this question so let me post this here for everyone to see. This error usually means you're missing compiler tools (headers actually) that have been removed from Xcode.

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

You can find them in /Library/Developer/CommandLineTools/Packages/ since their name might be different depending on your version of macOS in the future.

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

Assuming you're running macOS Mojave (10.14), you need to run:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

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

And an macOS-style package installer will start, asking you for your adminstrator password. This is an official Apple package and although it might be weird to install something out of a random directory, you can trust it. You don't have to take my word for it though. Apple buried this change in the Xcode 10 release notes and you can find their explanation here: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035623

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

I'll reproduce this here in case this link ever goes away or gets changed:

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

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:

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

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

或位于以下位置的命令行工具:

or the Command Line Tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

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

depending on which is selected using xcode-select.

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

The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at:

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

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 
> To make sure that you're using the intended version of the command line tools, run xcode-select -s or xcode select -s /Library/Developer/CommandLineTools after installing.

这篇关于MacOS“配置:错误:无法运行C编译程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆