c++ boost随机数

第一次使用boost库它就给我来了一个下马威!!在生成随机数的时候,报出下面一箩筐错误:

 

/usr/include/boost/random/uniform_int.hpp:111: undefined reference to `boost::random_device::operator()()'

/usr/include/boost/random/uniform_int.hpp:159: undefined reference to `boost::random_device::operator()()'

/usr/include/boost/random/uniform_int.hpp:241: undefined reference to `boost::random_device::operator()()'

./src/engine/local_engine/tools.o: In function `unsigned int boost::uniform_int<unsigned int>::generate<boost::random_device>(boost::random_device&, unsigned int, unsigned int, unsigned int)':

/usr/include/boost/random/uniform_int.hpp:111: undefined reference to `boost::random_device::operator()()'

/usr/include/boost/random/uniform_int.hpp:159: undefined reference to `boost::random_device::operator()()'

./src/engine/local_engine/tools.o:/usr/include/boost/random/uniform_int.hpp:241: more undefined references to `boost::random_device::operator()()' follow

./src/engine/local_engine/tools.o: In function `boost::thread_specific_ptr<boost::random_device>::delete_data::operator()(void*)':

/usr/include/boost/thread/tss.hpp:42: undefined reference to `boost::random_device::~random_device()'

collect2: ld returned 1 exit status

make: *** [GameRobotLibTHPokerNew] Error 1

 

通过求助狗狗的Google和微软的有病Bing,通过以下方式解决:

1、包含include和lib路径

/usr/local/src/boost_1_55_0
/usr/local/src/boost_1_55_0/stage/lib

 

2、使用链接选项

-lboost_system
-lboost_thread
-lboost_random

 

3、建立软连接(不知道安装的时候为啥木有创建,难道是RP问题~~)

ln -s /usr/local/src/boost_1_55_0/stage/lib/libboost_system.so.1.55.0 /usr/lib/libboost_system.so.1.55.0
ln -s /usr/local/src/boost_1_55_0/stage/lib/libboost_thread.so.1.55.0 /usr/lib/libboost_thread.so.1.55.0
ln -s /usr/local/src/boost_1_55_0/stage/lib/libboost_random.so.1.55.0 /usr/lib/libboost_random.so.1.55.0
sudo /sbin/ldconfig

 

搞定,收工。。

 

PS: boost库的安装方法详见:http://www.open-abc.com/ccode-206.html

posted @ 2013-12-05 15:09  hongmao  阅读(1064)  评论(0)    收藏  举报