在Red Hat Linux上使用g++ 4.4.7编译C++11

9

我已经尝试过以下方法:

g++ -std=c++11 my_file.cpp -o my_prog
g++ -std=c++0x ...
g++ -std=gnu++0x ... 

我一直收到这个消息:

error: unrecognized command line option

5
g++ 4.4.7 不支持 C++11,对吗? - Martin G
which g++ 报告了什么?g++ -v 又报告了什么? - Bill Lynch
2个回答

7

GCC中的C++0x/C++11支持

从这里可以看到,自gcc 4.7起支持C++11,而gcc 4.4则支持C++0x。

引用自GCC 4.4中实验性C++0x支持的状态:

GCC为即将发布的ISO C++标准C++0x提供了实验性支持。此支持可以通过使用-std=c++0x或-std=gnu++0x编译器选项来启用;前者禁用GNU扩展。

因此,应该使用-std=c++0x-std=gnu++0x


1

你的问题不是很清楚:

[11:51am][wlynch@apple /tmp] cat /etc/redhat-release 
CentOS release 6.5 (Final)
[11:51am][wlynch@apple /tmp] g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) 
[11:51am][wlynch@apple /tmp] g++ -std=c++0x simple.cc 
[11:51am][wlynch@apple /tmp]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接