在C ++ 11模式下使用GCC在FreeBSD上工作 [英] Getting GCC in C++11 mode to work on FreeBSD

查看:266
本文介绍了在C ++ 11模式下使用GCC在FreeBSD上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在FreeBSD 10上获得基于GCC的C ++ 11设置?似乎在FreeBSD的最新GCC版本附带的标准库是破碎的。我安装了端口 gcc49 ,然后尝试编译:

How do I get a working GCC-based C++11 setup on FreeBSD 10? It seems that the standard library that comes with recent GCC versions on FreeBSD is broken. I've installed the port gcc49 and then try to compile this:

#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 头。有意义,因为 gcc49 端口附带了相应的libstc ++。但是它似乎破碎,按上述错误。

The default include search path is /usr/local/lib/gcc49/include/c++/, which does contain the string header. Makes sense, because the gcc49 port ships with a corresponding libstc++. But it seems broken, per the above error.

这是一个已知的问题吗?有没有人在FreeBSD上为C ++ 11的工作设置了一个基于GCC的工具链?

Is this a known problem? Has anyone gotten a working setup of a GCC-based toolchain for C++11 on FreeBSD?

(注意:我知道Clang是默认但是在这种情况下,我特别希望支持一个基于GCC的工具链。)

(Note: I'm aware that Clang is the default compiler on FreeBSD 10. But in this case I'm specifically looking to support a GCC-based toolchain.)

推荐答案

p>将以下标志添加到g ++将使其工作:

Turns out that adding the following flags to g++ will make it work:

-D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH -D_GLIBCXX_USE_C99_MATH_TR1

这篇关于在C ++ 11模式下使用GCC在FreeBSD上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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