1

I'm trying to compile some code utilizing C++11's library on a linux server. The code compiles fine on my mac with this line in my makefile:

 CC = clang++ -std=c++11 -stdlib=libc++

However, when I try and compile the same code on a Linux server, with gcc version 4.8.1, I get the following error:

$ /usr/local/share/gcc481/bin/g++ -std=c++11 server.cpp
In file included from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/random:50:0,
                 from ellipse-graph.h:6,
                 from server.cpp:1:
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.h: In instantiation of 'class std::uniform_int_distribution<double>':
server.cpp:17:59:   required from here
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.h:1668:7: error: static assertion failed: template argument not an integral type
       static_assert(std::is_integral<_IntType>::value,
       ^
In file included from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/move.h:57:0,
                 from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/stl_pair.h:59,
                 from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/stl_algobase.h:64,
                 from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/vector:60,
                 from interval.h:4,
                 from vertex.h:4,
                 from ellipse-graph.h:4,
                 from server.cpp:1:
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/type_traits: In instantiation of 'struct std::make_unsigned<double>':
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.tcc:884:57:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = double; std::uniform_int_distribution<_IntType>::result_type = double]'
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.h:1770:51:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = double; std::uniform_int_distribution<_IntType>::result_type = double]'
server.cpp:20:40:   required from here
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/type_traits:1531:62: error: invalid use of incomplete type 'class std::__make_unsigned_selector<double, false, false>'
     { typedef typename __make_unsigned_selector<_Tp>::__type type; };
                                                              ^
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/type_traits:1495:11: error: declaration of 'class std::__make_unsigned_selector<double, false, false>'
     class __make_unsigned_selector;
           ^

It appears the issue is the header. When I look here https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x, at "26.5", it appears that gcc 4.8.1 doesn't support random number generation, unless I'm interpreting this incorrectly. How might I compile this file?

Nezo
  • 567
  • 4
  • 18
  • 1
    Change the compiler to a newer version. If you don't have admin rights, can try to download gcc and compile it from source in your home folder. – vsoftco Jun 05 '15 at 00:47
  • See this stackoverflow question: http://stackoverflow.com/questions/24852309/explicit-template-parameter-specification-for-ostream-operator-puzzling-compi – Scott 'scm6079' Jun 05 '15 at 00:48
  • @vsoftco wish it were that easy on a production server, but then you have to deal with the new compiler or backing glibc and glibc++ "breaking" older stuff. – user4581301 Jun 05 '15 at 00:52
  • @Scott'scm6079' That doesn't really give me a solution. It makes me realize that I should try and use clang++, but I don't know how to set up clang without root. – Nezo Jun 05 '15 at 01:06
  • If you can't upgrade gcc, maybe you could use [Boost.Random](http://www.boost.org/doc/libs/release/doc/html/boost_random.html) instead? That shouldn't involve very many code changes. – Praetorian Jun 05 '15 at 01:09
  • @Scott'scm6079' actually, thanks I figured it out from that. – Nezo Jun 05 '15 at 01:37
  • Awesome! :). Glad it helped. – Scott 'scm6079' Jun 05 '15 at 06:01

0 Answers0