Author Topic: undefined reference to `clock_gettime' and boost, please help me!  (Read 16203 times)

Offline polisbul

  • Multiple posting newcomer
  • *
  • Posts: 17
I've two computer, one with ubuntu 12.04, one with 13.04, and both with codeblocks 12.11.

If I compile with this shell script
Code
g++ -g -I/home/user/boost_1_50_0  -c main.cpp -o main.o
g++ main.o  /home/user/boost_1_50_0/bin.v2/libs/program_options/build/gcc-4.6/release/link-static/threading-multi/libboost_program_options.a /home/user/boost_1_50_0/bin.v2/libs/system/build/gcc-4.6/release/link-static/threading-multi/libboost_system.a /home/user/boost_1_50_0/bin.v2/libs/filesystem/build/gcc-4.6/release/link-static/threading-multi/libboost_filesystem.a /home/user/boost_1_50_0/bin.v2/libs/chrono/build/gcc-4.6/release/link-static/threading-multi/libboost_chrono.a   -lrt   -o software.out
everything works fine on both the computers, but if I set those 4 file in "link libraries", set the correct directory in "search directories", only in the 13.04 machine it works (without setting -lrt!), while on the 12.04 machine I get
In function `boost::chrono:: system_clock::now(): chrono.cpp:
undefined reference to `clock_gettime'
error.
and if I try to set -lrt option in "other linker settings", or in "other settings -> advanced options -> command line macro" directly in the command, I always get this error. What's the problem? I tried with g++ 4.6, 4.7, gcc too...

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: undefined reference to `clock_gettime' and boost, please help me!
« Reply #1 on: October 18, 2013, 03:56:53 pm »
and if I try to set -lrt option in "other linker settings", or in "other settings -> advanced options -> command line macro" directly in the command, I

what are you doing there? This is only for expert use. A normal user would never change there anything

To add search paths for headers do it under: Project->Build Options->Search Directories
To add linker or compiler options do it under: Project->Build Options ->Compiler Settings-> Other options / Project-> Build options->Linker Settings

can you post the full build log from the build log tab?

greetings

Offline polisbul

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: undefined reference to `clock_gettime' and boost, please help me!
« Reply #2 on: October 18, 2013, 04:09:47 pm »
Well, I found a solution, that is to change to command line macro for the link object to files for console executable, by substituting the line

Code
$linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs

with the line

Code
$linker $libdirs $link_objects $link_resobjects $libs $link_options -o $exe_output

Now it works fine.

I read on internet that g++ is quite picky about the order of options declaration, and the -lrt option should stay at the and of the linking invocation (just like in my script).