构建 C++ 在 OSX 10.9 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19575956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:58:29  来源:igfitidea点击:

Building C++ not working in OSX 10.9

c++macosgccosx-mavericks

提问by vladb

Update:

更新:

I solved the problem in the end by reinstalling command line tools, as shown in this link. Sorry for the trouble!

最后我通过重新安装命令行工具解决了这个问题,如此链接所示。抱歉,添麻烦了!

Initial question

初始问题

I have just upgraded to OSX Mavericks and I cannot make the compiler work anymore. I've been using gcc48 from macports with vim/sb2 and everything was working just fine. Now any library that I include gives tons of errors. I am not very experienced and I do not know what to do, or what to search for. I just want it to work like before. Here is what is says when compiling a basic "hello world" program:

我刚刚升级到 OSX Mavericks,我不能再让编译器工作了。我一直在使用带有 vim/sb2 的 macports 的 gcc48,并且一切正常。现在我包含的任何库都会出现大量错误。我不是很有经验,我不知道该做什么,或要搜索什么。我只是想让它像以前一样工作。以下是编译基本的“hello world”程序时所说的内容:

In file included from /opt/local/include/gcc48/c++/bits/postypes.h:40:0,
             from /opt/local/include/gcc48/c++/iosfwd:40,
             from /opt/local/include/gcc48/c++/ios:38,
             from /opt/local/include/gcc48/c++/ostream:38,
             from /opt/local/include/gcc48/c++/iostream:39,
             from ceva.cpp:1:
/opt/local/include/gcc48/c++/cwchar:44:19: fatal error: wchar.h: No such file or directory
#include <wchar.h>

If you need any information, tell me and I will provide it to you. Thank you for your patience!

如果您需要任何信息,请告诉我,我会提供给您。感谢您的耐心等待!

回答by Petesh

[Added 2019 - Mojave/Catalina] XCode 10 has removed the placement of headers in /usr/include, even with the command line tools. If you want headers, and you're on you should be able to install a transitional package, which is available on Mojave. This package is not present on the Catalina. The headers are within the SDK for the appropriate release.

[2019 年添加 - Mojave/Catalina]/usr/include即使使用命令行工具,XCode 10 也删除了 中标头的位置。如果你想要标题,并且你在,你应该能够安装一个过渡包,它在 Mojave 上可用。Catalina 上没有此包。标头位于相应版本的 SDK 中。

XCode 5/Mavericks have changed the defaults for where headers are located.

XCode 5/Mavericks 更改了标头所在位置的默认值。

On prior versions of Mac OS X / XCode you would have found headers in /usr/include.

在以前版本的 Mac OS X/XCode 上,您会在/usr/include.

When you built gcc on the older release it picked up the headers from that location, and looks for them there now when you try to build code.

当您在旧版本上构建 gcc 时,它会从该位置获取头文件,并在您尝试构建代码时在那里查找它们。

The problem is that the files are not there; they're somewhere under /Applications/Xcode.app/Contents/Developer.

问题是文件不存在;他们在某处/Applications/Xcode.app/Contents/Developer

You could futz about with a spec file to get it working consistently again, but the sanest thing to do is rebuild gcc.

您可以使用规范文件进行测试以使其再次一致地工作,但最明智的做法是重建 gcc。

As has been mentioned as well, you can install the command line tools using xcode-select --install, which will reinstall the developer tools, including the headers in /usr/include.

如前所述,您可以使用 安装命令行工具xcode-select --install,这将重新安装开发人员工具,包括/usr/include.

I tend to reinstall things like gcc when I upgrade my operating system as I encounter other errors due to changes in the environment. This is just a habit I've formed. It may not be the best habit, but it's saved me pain on numerous occasions.

我在升级操作系统时倾向于重新安装 gcc 之类的东西,因为我遇到了由于环境变化而导致的其他错误。这只是我养成的习惯。这可能不是最好的习惯,但它在很多情况下都让我免于痛苦。

[added 2017] As an addendum, if you install the command line tools, then the headers will be placed in /usr/includeas well. The command to install the command line tools is xcode-select --install- this will allow you to use most compilers without having to specify the location of the headers manually.

[2017 年添加] 作为附录,如果您安装了command line tools,则标头也将放置在其中/usr/include。安装命令行工具的命令是xcode-select --install- 这将允许您使用大多数编译器而无需手动指定头文件的位置。

回答by uplearnedu.com

This is how I got it working on Mac osx Mavericks:

这就是我在 Mac osx Mavericks 上使用它的方式:

  1. Open terminal

  2. type --> xcode-select --install

  3. A pop-up windows will apear asking you about install tools

  4. choose install tools

  5. wait install to finish

  1. 打开终端

  2. 类型 --> xcode-select --install

  3. 将出现一个弹出窗口,询问您有关安装工具的信息

  4. 选择安装工具

  5. 等待安装完成

回答by uplearnedu.com

Here is a manual method for updating XCode on OS X Mavericks:

这是在 OS X Mavericks 上更新 XCode 的手动方法:

  1. Go into the developers site http://developer.apple.com

  2. Then go to Downloads for Apple developers and there is a command line tools installer for Mavericks — here's the link (but you'll need a developers account for the link to work) http://developer.apple.com/downloads/index.action?q=xcode

  1. 进入开发者网站http://developer.apple.com

  2. 然后转到 Apple 开发人员的下载,这里有一个适用于 Mavericks 的命令行工具安装程序 - 这是链接(但您需要一个开发人员帐户才能使该链接工作)http://developer.apple.com/downloads/index。动作?q=xcode

回答by Jialin Zou

I'm using MacOs Sierra 10.12.4, got the same problem. I solved it by using:

我正在使用 MacOs Sierra 10.12.4,遇到了同样的问题。我通过使用解决了它:

/usr/bin/gcc

回答by juhoautio

For me the fix was to uninstall old broken gcc:

对我来说,修复方法是卸载旧的损坏的 gcc:

brew uninstall gcc@5

I noticed paths like /usr/local/Cellar/gcc@5in build output, while gcc@8was also installed and is the one that was supposed to be used.

我注意到/usr/local/Cellar/gcc@5构建输出中的路径,而 whilegcc@8也已安装,并且是应该使用的路径。