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?
The flag
-std=c++0xgives you access to whatever c++11 functionality is implemented in your version of gcc. For random number distributions, c++11 has the headerrandom. You do not need thetr1namespace when using c++11.The
tr1version of random is in includetr1/random, and everything there is under thestd::tr1namespace. To access this you do not need thec++0xflag.To be clear:
For TR1 random numbers:
#include <tr1/random>and usestd::tr1::normal_distribution.For c++11 random numbers: compile with flag
c++0x, then#include <random>and usestd::normal_distribution.