3

将 boost 库从版本 1.52 升级到 1.53 后,在 Linux 下使用 GCC 构建时出现以下链接器错误。相同的应用程序在 Windows 下使用 VC++10 和 boost 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

4

1 回答 1

3

它基本上说clock_gettime链接器找不到该功能。这个函数在rt库中,所以添加-lrt到链接器命令行。

于 2013-02-12T15:13:11.627 回答