xcode MacOS 的“-std=gnu++0x”选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10480654/
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-09-15 00:12:50  来源:igfitidea点击:

"-std=gnu++0x"option for MacOS

c++xcodegccc++11osx-lion

提问by Joachim

I'm trying to compile a CMake project which uses

我正在尝试编译一个使用的 CMake 项目

set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wall -std=gnu++0x")

in the CMakeLists.txt file under MacOS X Lion. I have installed XCode 4.2.1. but the compiler fails with this:

在 MacOS X Lion 下的 CMakeLists.txt 文件中。我已经安装了 XCode 4.2.1。但是编译器失败了:

cd something/src/lib && /usr/bin/c++   -Dlib_ginacra_EXPORTS -Wall -std=gnu++0x -fPIC   -o CMakeFiles/lib_ginacra.dir/utilities.cpp.o -c something/src/lib/utilities.cpp
cc1plus: error: unrecognized command line option "-std=gnu++0x"

The compiler's verion is:

编译器的版本是:

c++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)

回答by Jonathan Wakely

GCC 4.2 is ancient, but Apple don't ship a newer version.

GCC 4.2 很古老,但 Apple 没有发布更新的版本。

You can either install a modern GCC from somewhere like Mac Ports (which is probably simpler and quicker) or build it yourself following the instructions at http://gcc.gnu.org/wiki/InstallingGCC

您可以从 Mac Ports 之类的地方安装现代 GCC(这可能更简单快捷),也可以按照http://gcc.gnu.org/wiki/InstallingGCC 上的说明自行构建

回答by Alex Fairchild

For Lion users facing this issue:

对于面临此问题的 Lion 用户:

Download and Install the MacPorts-2.2.1-10.7-Lion.pkgMacPorts installer package from here

这里下载并安装MacPorts-2.2.1-10.7-Lion.pkgMacPorts 安装程序包

in a terminal, search for newer GCC versions:

在终端中,搜索较新的 GCC 版本:

$  port search --name --glob 'gcc*' 

install a newer version (I went with gcc5)

安装较新版本(我使用 gcc5)

$  sudo port install gcc5

get the name of your new version, and set it as default

获取新版本的名称,并将其设置为默认值

$ port select --list gcc

Available versions for gcc:
    llvm-gcc42
    mp-gcc5
    none (active)

$ sudo port select --set gcc mp-gcc5

open a new terminal and validate you're updated:

打开一个新终端并验证您已更新:

$ c++ --version
c++ (MacPorts gcc5 5.2.0_0) 5.2.0

回答by Aman Bansal

Most of you getting that error "cc1plus: error: unrecognized command line option -std=gnu++0x" while installing nodejs extension which requires C++ compilation with node-gyp. So how to solve this error so here is the solution. Basically you get these errors because of Nodejs different version as?many node libraries requires C or C++ compilation while installing. So Nodejs older version?uses python 2.7with?gcc compiler less than version 4.2 but Nodejs?newer version uses gcc44compiler that's why you get above error while?installing any nodejs library.

大多数人在安装需要使用node-gyp 进行 C++ 编译的 nodejs 扩展时都会收到错误“cc1plus:错误:无法识别的命令行选项 -std=gnu++0x”。那么如何解决这个错误所以这里是解决方案。基本上你会因为 Nodejs 版本不同而得到这些错误?许多节点库在安装时需要 C 或 C++ 编译。所以Nodejs旧版本?使用python 2.7gcc编译器低于 4.2 版,但 Nodejs?较新的版本使用gcc44编译器,这就是为什么在安装任何 nodejs 库时出现上述错误的原因。

So you need to degrade your nodejs and node-gyp version and specify the python version if you have multiple python versions installed on your system and then you will not get above error anymore.

因此,如果您的系统上安装了多个 python 版本,您需要降级 nodejs 和 node-gyp 版本并指定 python 版本,然后您将不再出现上述错误。

Click here to see full tutorial

单击此处查看完整教程