3

After upgrading the boost libraries form version 1.52 to 1.53 I get the following linker error when building with GCC under Linux. The same application builds fine under Windows with VC++10 and 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

I built the boost libraries like this:

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

My GCC version is 4.7.2

3
  • Shouldn't this be fixed in boost? If boost needst lrt, it's his job to link against it, not user's?
    – matemaciek
    Apr 16, 2013 at 11:19
  • On what platform are you building? Apr 16, 2013 at 17:10
  • That was on Debian Wheezy Apr 17, 2013 at 6:32

1 Answer 1

3

It basically says that clock_gettime function is not found by the linker. This function is in rt library, so add -lrt to the linker command line.

2
  • In case someone struggles with this as-well using Codeblocks, there you just have to add -rt (NOT -lrt) to the top of "Other linker options".
    – AudioDroid
    Nov 27, 2013 at 19:17
  • Actually the above is a false statement, -lrt or -rt doesn't work for me somehow. :-(
    – AudioDroid
    Nov 27, 2013 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.