Opened 10 years ago

Closed 10 years ago

#8448 closed Bugs (invalid)

thread library needs linking against -lrt

Reported by: Maciej Sokołowski <matemaciek@…> Owned by: viboes
Milestone: To Be Determined Component: chrono
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

I have a similar problem to one described here: http://stackoverflow.com/questions/14835605/linking-with-gcc-fails-after-switching-boost-version-from-1-52-to-1-53

I'm able to fix it by adding -lrt in my build system, but I guess it's a bug in boost build system - if boost needs -lrt, it should have been already linked against it, right?

I build boost like this:

./bootstrap.sh --without-icu
./b2 toolset=gcc variant=release link=static threading=multi runtime-link=shared --with-system --with-filesystem --with-test --with-thread --prefix=/some/path install

Change History (8)

comment:1 by viboes, 10 years ago

Component: Building Boostchrono
Owner: set to viboes
Status: newassigned

On what platform are you building? Which error do you get?

comment:2 by Maciej Sokołowski <matemaciek@…>, 10 years ago

Exact output:

/[...]/boost/1_53_0/linux64.gcc-4.7/libboost_thread.a(thread.o): In function `boost::this_thread::hiden::sleep_for(timespec const&)':
thread.cpp:(.text+0xc48): undefined reference to `clock_gettime'
/[...]/boost/1_53_0/linux64.gcc-4.7/libboost_thread.a(thread.o): In function `boost::this_thread::hiden::sleep_until(timespec const&)':
thread.cpp:(.text+0x14b6): undefined reference to `clock_gettime'
thread.cpp:(.text+0x1525): undefined reference to `clock_gettime'
thread.cpp:(.text+0x1594): undefined reference to `clock_gettime'
thread.cpp:(.text+0x1603): undefined reference to `clock_gettime'
/home/msokolowski/gg_repos/phoenix-common/ggclient-3rdparty/boost/1_53_0/linux64.gcc-4.7/libboost_thread.a(thread.o):thread.cpp:(.text+0x1672): more undefined references to `clock_gettime' follow
collect2: error: ld returned 1 exit status

comment:3 by Maciej Sokołowski <matemaciek@…>, 10 years ago

uname -a:

Linux KOMUNIKATOR-11 3.5.0-26-generic #42-Ubuntu SMP Fri Mar 8 23:18:20 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

gcc 4.7.2, platfrom: Ubuntu 12.10

comment:4 by viboes, 10 years ago

The Boost.Chrono build Jamfile contains

    : requirements
        <target-os>freebsd:<linkflags>"-lrt"
        <target-os>linux:<linkflags>"-lrt -lpthread"
        <toolset>pgi:<linkflags>"-lrt"


Are you linking with boost_chrono? Could you show the link command line?

comment:5 by Maciej Sokołowski <matemaciek@…>, 10 years ago

I'm not linking with boost_chrono (should I? why?):

/usr/bin/c++ -pedantic -Wall -g [a bunch of our .o files here] -o outputFile -rdynamic /boost/path/libboost_filesystem.a /boost/path/libboost_system.a /boost/path/libboost_thread.a

comment:6 by viboes, 10 years ago

If you don't want to use the time related functions based on Boost.Chrono you can define BOOST_THREAD_DONT_USE_CHRONO. From Boost.Thread documentation:

Boost.Chrono

Boost.Thread uses by default Boost.Chrono for the time related functions and define BOOST_THREAD_USES_CHRONO if BOOST_THREAD_DONT_USE_CHRONO is not defined. The user should define BOOST_THREAD_DONT_USE_CHRONO for compilers that don't work well with Boost.Chrono. 

Otherwise you need to link with it, or define the macros needed to make Boost.Chrono header only. From Boost.Chrono documentation:

Building Boost.Chrono

Boost.Chrono can be configured as a header-only library defining BOOST_CHRONO_HEADER_ONLY. However Boost.Chrono depends on the non header-only library Boost.System, so that you will need to link with boost_system.

Boost.System has un undocumented feature (use of macro BOOST_ERROR_CODE_HEADER_ONLY) to make it header only, but it is buggy (see #7347 duplicate symbol while BOOST_ERROR_CODE_HEADER_ONLY is defined)

If BOOST_CHRONO_HEADER_ONLY is not defined you need to compile it and build the library before use, for example using:

bjam libs/chrono/build

comment:7 by viboes, 10 years ago

Could I close this ticket?

comment:8 by viboes, 10 years ago

Resolution: invalid
Status: assignedclosed
Note: See TracTickets for help on using tickets.