Boost logo

Boost Users :

Subject: Re: [Boost-users] libboost_date_time: undefined reference to __sync_fetch_and_add_4
From: Carsten Raas (carsten.raas_at_[hidden])
Date: 2009-04-03 19:29:49


Hi Tom!

Tom Fogal <tfogal_at_[hidden]> writes:
> Carsten Raas <carsten.raas_at_[hidden]> writes:
>> -----------------------------------------------------------------
>> Shared linking:
>> # icpc -I /opt/boost/1.38/intel/include conftest.cpp
>> -L /opt/boost/1.38/intel/lib -lboost_date_time
>>
>> /opt/boost/1.38/intel/lib/libboost_date_time.so:
>> undefined reference to `__sync_fetch_and_add_4'
>> -----------------------------------------------------------------
>> Shared linking with gcc:
>>
>> # g++ -I /opt/boost/1.38/intel/include conftest.cpp \
>> -L /opt/boost/1.38/intel/lib -lboost_date_time
>>
>> /opt/boost/1.38/intel/lib/libboost_date_time.so:
>> undefined reference to `__sync_fetch_and_add_4'
>> collect2: ld returned 1 exit status
>> -----------------------------------------------------------------
>
> This is an internal function for gcc's atomics extensions.
>
> http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Atomic-Builtins.html

Thanks for the hints!

Just to make this point clear: The boost build is done completely with
the Intel compiler suite (using the intel-linux toolset):

./configure --prefix=/opt/boost/1.38/intel --with-toolset=intel-linux

bjam --toolset=intel-linux -prefix=/opt/boost/1.38/intel \
      --build-type=complete --with-date_time install

The only thing I changed was
        tools/build/v2/tools/intel-linux.jam
to get rid of all these warnings:

icpc: command line remark #10010: option '-Ob' is deprecated and will be
removed in a future release. See '-help deprecated'

Thus I replaced -Obx with -inline-level=x (x=0,1,2).
This makes the build free of warnings.

> Can you try adding -lgcc (IIRC; maybe lgcc_s?) to your link line?

I checked this, but both (-lgcc and -lgcc_s) are already in the linker
call of icpc as well as in the g++ linking (visible when using the -v
switch). Adding the libraries in addition (in various orders) did not help.

> Looks like the more global problem is that boost_date_time is using
> this symbol, but was not linked against it at build time. It's a bit
> strange that your compiler isn't adding this implicitly though...

What is confusing for me is that the static libraries work:

While
        icpc -I /opt/boost/1.38/intel/include \
        -L /opt/boost/1.38/intel/lib conftest.cpp -lboost_date_time
fails, this one works:
        icpc --static -I /opt/boost/1.38/intel/include \
        -L /opt/boost/1.38/intel/lib conftest.cpp -lboost_date_time

The same for using g++ instead of icpc (for the demo program).

-Carsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net