如何在FreeBSD 10上获得基于GCC的有效C++ 11设置?似乎FreeBSD上最新的GCC版本随附的标准库已损坏。我已经安装了gcc49
端口,然后尝试编译它:
#include <string>
int main()
{
auto str = std::to_string(42);
str = std::to_string(42ull);
str = std::to_string(4.2);
str.clear();
return 0;
}
这给我一个错误:
g++49 -v -std=c++11 foo.cc
Using built-in specs.
COLLECT_GCC=g++49
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/lto-wrapper
Target: x86_64-portbld-freebsd10.0
Configured with: ./../gcc-4.9-20141022/configure --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc49 --libexecdir=/usr/local/libexec/gcc49 --program-suffix=49 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gc
c49/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --with-ecj-jar=/usr/local/share/java/ecj-4.5.jar --enable-languages=c,c++,objc,fortran,java --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc49 --build=x86_64-portbld-freebsd10.0
Thread model: posix
gcc version 4.9.2 20141022 (prerelease) (FreeBSD Ports Collection)
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/local/libexec/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/cc1plus -quiet -v foo.cc -quiet -dumpbase foo.cc -mtune=generic -march=x86-64 -auxbase foo -std=c++11 -version -o /tmp//ccbNFhtI.s
GNU C++ (FreeBSD Ports Collection) version 4.9.2 20141022 (prerelease) (x86_64-portbld-freebsd10.0)
compiled by GNU C version 4.9.2 20141022 (prerelease), GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/../../../../../x86_64-portbld-freebsd10.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/gcc49/include/c++/
/usr/local/lib/gcc49/include/c++//x86_64-portbld-freebsd10.0
/usr/local/lib/gcc49/include/c++//backward
/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/include
/usr/local/include
/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/include-fixed
/usr/include
End of search list.
GNU C++ (FreeBSD Ports Collection) version 4.9.2 20141022 (prerelease) (x86_64-portbld-freebsd10.0)
compiled by GNU C version 4.9.2 20141022 (prerelease), GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8405316ee381c37148f55a17e42da47a
foo.cc: In function 'int main()':
foo.cc:5:14: error: 'to_string' is not a member of 'std'
auto str = std::to_string(42);
^
foo.cc:6:9: error: 'to_string' is not a member of 'std'
str = std::to_string(42ull);
^
foo.cc:7:9: error: 'to_string' is not a member of 'std'
str = std::to_string(4.2);
^
默认的包含搜索路径是
/usr/local/lib/gcc49/include/c++/
,它确实包含string
header 。这是有道理的,因为gcc49
端口附带了相应的libstc++。但是,根据上述错误,它似乎已损坏。这是一个已知问题吗?有没有人在FreeBSD上获得针对C++ 11的基于GCC的工具链的有效设置?
(注意:我知道Clang是FreeBSD 10上的默认编译器。但是在这种情况下,我特别希望支持基于GCC的工具链。)
最佳答案
事实证明,向g++添加以下标志将使其起作用:
-D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH -D_GLIBCXX_USE_C99_MATH_TR1
关于c++ - 使GCC以C++ 11模式在FreeBSD上运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26832199/