3

I installed gcc49 on FreeBSD10.1. I am trying to use it for C++11 development. However, every time I'm compiling some C++11 valid code (yes I use -std=c++11) that uses specific math functions, it spits out errors, such as

error: std::round is not a member of std
/usr/include/math.h 

For example, here:

#include <cmath>
#include <iostream>
int main()
{
 std::cout << std::round(10.1) << std::endl;
}

So it seems it tries to use the old include files that came with FreeBSD, and not the ones corresponding to the new gcc from /usr/local/lib/gcc49/include

I tried setting CPLUS_INCLUDE_PATH to /usr/local/lib/gcc49/include with no luck, the system still tries to search /usr/include instead.

I saw that this may be a bug in FreeBSD g++, Getting GCC in C++11 mode to work on FreeBSD however even using the -D_GLIBCXX_USE_C99 as suggested in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194929 doesn't fix the problem for math functions.

The weirdest thing is that I can compile any other C++11 functions not from <cmath>, like std::stol, but have to use the -D_GLIBCXX_USE_C99 flag as mentioned in the bug report above.

Any idea how to make g++ fully functional with C++11 on FreeBSD 10.1?

asked Feb 9, 2015 at 17:01
12
  • Do you ask for C++11? Commented Feb 9, 2015 at 17:11
  • @Deduplicator yes, I need C++11 support Commented Feb 9, 2015 at 19:51
  • @mvw, I tried that, same issue, it seems to not being able to recognize the math part of the C++11 standard library Commented Feb 9, 2015 at 19:52
  • @vsoftco round is not a member of std. Use it without std::. It may be a GCC extension. Commented Feb 10, 2015 at 13:15
  • en.cppreference.com/w/cpp/numeric/math/round it is, since C++11. Commented Feb 10, 2015 at 13:17

1 Answer 1

1

It works out of box on 10.1, you shouldn't need any hacks. Of course, it only works with -std=c++11, as std::round is only available since 11 standard (see http://en.cppreference.com/w/cpp/numeric/math/round).

$ freebsd-version -ku
10.1-RELEASE
10.1-RELEASE
$ cat test.cc
#include <cmath>
#include <iostream>
int main() {
 std::cout << std::round(10.1) << std::endl;
}
$ g++5 -std=c++11 -o test test.cc
$ ./test
10

Note: gcc was compiled from ports, package was reported to not work. Probably because packages for 10.1 are at the time of writing compiled on 10.0, which still had c++11 compatibility issues.

answered Feb 24, 2015 at 19:52
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, I marked the question with gcc5 but I used gcc49. Will try gcc5.
I just used the latest stable 10.1/amd64 version (downloaded the installer image from FreeBSD's web site freebsd.org/where.html) inside a VirtualBox, and installed g++49 with pkg install lang/gcc49. The code above didn't compile. How did you install the compiler? I did not compile it from source.
I build everything from ports. Packages could be broken because they are built on 10.0.
thanks, I should then compile the ports. I tested it quickly using pkg install because I just wanted to see if my app is portable without issues on FreeBSD. You should mention in the answer that you used the ports, as using pkg install doesn't seem to work.

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.