将升压版本从1.52切换到1.53后,与GCC的链接失败

时间:2013-02-12 15:10:29

标签: gcc boost linker boost-thread

将版本1.52的boost库升级到1.53后,在Linux下使用GCC构建时出现以下链接器错误。使用VC ++ 10在Windows下构建相同的应用程序并提升1.53。

Invoking: GCC C++ Linker
g++ -L"/home/robert/boost_1_53_0/stage/lib" -L/usr/lib -o "MyApp"  ./myObjectFile.o -lboost_log_setup-mt-s -lboost_log-mt-s -lboost_thread-mt-s -lboost_system-mt-s -lboost_regex-mt-s -lcryptopp -lboost_date_time-mt-s -lpthread -ldl -lboost_filesystem-mt-s
/home/robert/boost_1_53_0/stage/lib/libboost_thread-mt-s.a(thread.o): In function `boost::this_thread::hiden::sleep_for(timespec const&)':
thread.cpp:(.text+0xc10): undefined reference to `clock_gettime'
/home/robert/boost_1_53_0/stage/lib/libboost_thread-mt-s.a(thread.o): In function `boost::this_thread::hiden::sleep_until(timespec const&)':
thread.cpp:(.text+0x1425): undefined reference to `clock_gettime'
thread.cpp:(.text+0x14cd): undefined reference to `clock_gettime'
thread.cpp:(.text+0x159c): undefined reference to `clock_gettime'
thread.cpp:(.text+0x1684): undefined reference to `clock_gettime'
/home/robert/boost_1_53_0/stage/lib/libboost_thread-mt-s.a(thread.o):thread.cpp:(.text+0x176e): more undefined references to `clock_gettime' follow
collect2: error: ld returned 1 exit status

我构建了这样的boost库:

./bootstrap.sh --with-toolset=gcc
./b2 --layout=tagged variant=debug,release link=static runtime-link=static cxxflags=-std=c++0x

我的GCC版本是4.7.2

1 个答案:

答案 0 :(得分:3)

它基本上表示链接器找不到clock_gettime函数。此函数位于rt库中,因此将-lrt添加到链接器命令行。