【问题标题】:Getting GCC in C++11 mode to work on FreeBSD让 GCC 在 C++11 模式下在 FreeBSD 上工作
【发布时间】:2015-01-06 01:43:43
【问题描述】:

如何在 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 标头。有道理,因为gcc49 端口附带了相应的 libstc++。但根据上述错误,它似乎坏了。

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

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

【问题讨论】:

标签: c++ c++11 gcc freebsd libstdc++


【解决方案1】:

事实证明,将以下标志添加到 g++ 将使其工作:

-D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH -D_GLIBCXX_USE_C99_MATH_TR1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多