Problems with g++5.4 which do not happen on Ubuntu

When trying to compile the following C++ snippet with gcc 5.4 without any flags I get an error (as expected).

Code:
#include <string>
#include <iostream>

int main(){
  std::cout << std::to_string(0) << "\n";
  return 0;
}

error:
Code:
$ g++-5 test.cpp
test.cpp: In function ‘int main()’:
test.cpp:6:18: error: ‘to_string’ is not a member of ‘std’


When I use the `-std=c++14` flag on Ubuntu 16.04.2 LTS it compiles and runs fine. Even with the flag I get the same error as before on FreeBSD, even with what is supposed to be the same version of gcc:

Code:
$ g++5 --version
g++5 (FreeBSD Ports Collection) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++5 -std=c++14 test.cpp                                                                                                        test.cpp: In function 'int main()':
test.cpp:6:18: error: 'to_string' is not a member of 'std'
     std::cout << std::to_string(0) << "\n";

On Ubuntu:
Code:
% g++-5 --version
g++-5 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Does anyone have an explanation for this different behavour and a suggestion on how I can get this to run? (This is just a minimal example of trying to get https://github.com/clangen/musikcube to compile on FreeBSD.)
 
Not much of a programmer and I certain have no experience with GCC 5.4 but you typically need to supply -I/usr/local/include and -L/usr/local/lib on FreeBSD. I'm not sure if those are the correct directories because you can install different versions of GCC next to each other. If you don't supply a path for includes and libraries GCC only looks in /usr/{include,lib}.
 
Back
Top