Doesn't link to clock_gettime

Doesn't link to clock_gettime

After upgrading GCC from Ubuntu repository, TBB projects refuse to link.

$ g++ fibonacci.cpp -ltbb
/usr/bin/ld: /tmp/cctNLcQ2.o: undefined reference to symbol 'clock_gettime@@GLIBC_2.2.5'
/usr/bin/ld: note: 'clock_gettime@@GLIBC_2.2.5' is defined in DSO //lib64/ so try adding it to the linker command line
//lib64/ could not read symbols: Invalid operation
collect2: ld returned 1 exit status

Adding -lrt to the comand line as the error messages suggets fixes the problem. I am not sure what is going. Could it be because of borken GCC installation?

12 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

TBB binaries depend on certain versions of GCC (more exactly, on shared libraries shipped with these versions). In case you updated GCC from 3.x to 4.x, you likely need to link with a different TBB library than before. But if the update is within GCC 4.x (for example from 4.2 to 4.5), it's not the case.

Another guess is that the previous version of GCC was somehow configured to automatically link with librt.

It looks this happens with default gcc 4.5.x installed on the latest fedora and ubuntuwe will change makefiles to support this.--Vladimir


I'm having the same problem on mint 14 and gcc4.7 with tbb4.1. How is this suposed to work? Should tbb automatically link the correct lib or do I need to do it manually when linking tbb into my executable? It would be nice if tbb did this since librt is non-standard and unavailable on e.g. osx so I would need to build/change the configure stuff for my app depending on some dependency inside tbb...

Thx, Alex

Hello Alex

There is a dependency from in the binaries, so the library should be picked up by ld. what tbb version do you use (build date) that does not work in this way?
Regarding OSX-do you try to  use linux binaries on mac? why do you need to link with librt there? our libraries do not link with this library on mac.


Hi Vladimir,

on OSX librt is not requested by tbb (or anything) but when manually linking to librt on linux portability is destroyed.

I'm building tbb from source but I renamed the root directory, how can I figure out my exact version?

I have made 2 minor changes to the sources:

 - I redirect calls to pthreads through the boehm garbage collector by including an alternative pthread.h

 - I link boehm's libs

Apparently, the ref to librt is missing:

aherz@aherz-Precision-T1500:~/funky/funkyimp/lib$ ldd =>  (0x00007fff38fff000) => /lib/x86_64-linux-gnu/ (0x00007fe96ed49000) => /lib/x86_64-linux-gnu/ (0x00007fe96eb2b000) => /usr/lib/x86_64-linux-gnu/ (0x00007fe96e827000) => /lib/x86_64-linux-gnu/ (0x00007fe96e611000) => /lib/x86_64-linux-gnu/ (0x00007fe96e251000)
    /lib64/ (0x00007fe96f1a0000) => /lib/x86_64-linux-gnu/ (0x00007fe96df55000)
aherz@aherz-Precision-T1500:~/funky/funkyimp/lib$ ldd =>  (0x00007fff9edff000) => /lib/x86_64-linux-gnu/ (0x00007f9bb2a0e000) => /lib/x86_64-linux-gnu/ (0x00007f9bb27f0000) => /lib/x86_64-linux-gnu/ (0x00007f9bb2431000)
    /lib64/ (0x00007f9bb2e63000)


Alexander Herz wrote:

I'm building tbb from source but I renamed the root directory, how can I figure out my exact version?


# strings | grep INTERFACE VERSION

And did you use tbb's build system from that package to build the library? Other words is -lrt still in options you passed to the linker when you were building the library?


I'm building using tbb's build system (just calling make in the root dir).

I added the following in build/Makefile.tbb to use the garbage collector:

LIB_LINK_FLAGS  += -L$(tbb_root)/../boehm/bdwgc/.libs -lgccpp -lgc

CPLUS_FLAGS += -I$(tbb_root)/../pthread_redirect #-L$(tbb_root)/../boehm/bdwgc/.libs -lgccpp -lgc

The rest is unchanged. It's version 6.1.


make -n gives

g++ -fPIC -o concurrent_hash_map.o concurrent_queue.o concurrent_vector.o dynamic_link.o itt_notify.o cache_aligned_allocator.o pipeline.o queuing_mutex.o queuing_rw_mutex.o reader_writer_lock.o spin_rw_mutex.o spin_mutex.o critical_section.o task.o tbb_misc.o tbb_misc_ex.o mutex.o recursive_mutex.o condition_variable.o tbb_thread.o concurrent_monitor.o semaphore.o private_server.o rml_tbb.o task_group_context.o governor.o market.o arena.o scheduler.o observer_proxy.o tbb_statistics.o tbb_main.o concurrent_vector_v2.o concurrent_queue_v2.o spin_rw_mutex_v2.o task_v2.o   -ldl -lpthread -lrt -shared -Wl, -m64 -L../../../boehm/bdwgc/.libs -lgccpp -lgc  -Wl,--version-script,tbb.def

So -lrt is specified but there seems to be no effect.


Hi again,

I had a look at the tbb sources and found the problem. clock_gettime is not used in any cpp file if __linux__ is defined (only in headers), so the linker discards -lrt as no dependencies to that in the object files exist. By adding something like the following in e.g. tbb_thread.cpp the problem is solved (and the dep to librt is added to

#if __linux__

tbb_thread.cpp uses tick_count::now();, but only if _WIN32||_WIN64 is defined, not for __linux__.

Is this fixed in tbb 4.2?

Regards, Alex

hello Alex,

No, situation is the same in TBB 4.2. On ubuntu-based systems it is needed to use -lrt in case tbb::tick_count is used. We are trying to find out what should be set to linker in order to keep this dependency.

Thanks for the example. We need to find a good place to put such code because a good compiler should remove such standalone function on the optimization step and the issue would revert to previous one.


Libtool documentation says that default value of link_all_deplibs variable is ‘unknown’, which is a synonym for ‘yes’.

It looks that Debian/Ubuntu has changed default behavior of libtool and has not documented this.

See for details.


Leave a Comment

Please sign in to add a comment. Not a member? Join today