7

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;
}

This gives me an error:

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);
 ^

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.

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

(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.)

asked Nov 9, 2014 at 19:16
4
  • Is this in any way related? stackoverflow.com/questions/12975341/… Commented Nov 9, 2014 at 19:19
  • Doesn't freebsd have a bug tracker? Commented Nov 9, 2014 at 22:08
  • The FreeBSD bug tracker is indeed a better place for this discussion. Voting to close. Commented Nov 10, 2014 at 17:29
  • bugs.freebsd.org/bugzilla/show_bug.cgi?id=194929 now contains a workaround Commented Dec 26, 2014 at 15:57

1 Answer 1

8

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
answered Mar 18, 2015 at 6:32
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.