Search code examples
c++gcccmaketr1

tr1/normal_distribution: No such file or directory


I'm trying to use TR1 for some C++ project. Unfortunately I get an error and don't understand why or how I should do it correctly! I'm working under Linux with gcc 4.4.5.

I get the error

myfile.cpp:21:35: error: tr1/normal_distribution: No such file or directory     

The TR1 file I need is imported via:

#include <tr1/normal_distribution>

in CMakeLists.txt I turn on TR1 support (-std=c++0x)

SET (CMAKE_CXX_FLAGS "-Wall -std=c++0x -DNDEBUG -O3 -march=nocona -msse4.2")  

Any idea what I'm doing wrong?


Solution

  • The flag -std=c++0x gives you access to whatever c++11 functionality is implemented in your version of gcc. For random number distributions, c++11 has the header random. You do not need the tr1 namespace when using c++11.

    The tr1 version of random is in include tr1/random, and everything there is under the std::tr1 namespace. To access this you do not need the c++0x flag.

    To be clear:

    For TR1 random numbers: #include <tr1/random> and use std::tr1::normal_distribution.

    For c++11 random numbers: compile with flag c++0x, then #include <random> and use std::normal_distribution.