3

I am compiling a C++ project on Ubuntu 12.04 and I get a linking error stating

undefined reference to `clock_gettime@GLIBC_2.17'

undefined reference to `clock_getres@GLIBC_2.17'

I read a lot of threads about this issue and I tried all the usual solutions (separately). Such as adding the -lrt flag to the g++ command line (I tried in the beginning and in the end), setting the cmake linker flags variables to -lrt, adding the librt.so location to the link_directories variable or even to the target_link_libraries. None of this worked.

When I run ldd --version I get

ldd (Ubuntu EGLIBC 2.15-0ubuntu10.12) 2.15

And for what I understood from research this is the last glibc version for Ubuntu 12.04. But the error references to glibc 2.17... So My question is: Am I getting this error because of the gclib version? Is there any way I can get a more recent version for Ubuntu 12.04?

Thank you in advance!

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
ecnl
  • 31
  • 1
  • 3
  • Seems like your project needs `libc2.17`. Or could it be the g++ (or gcc) you have installed? The first step would be to determine who needs this newer libc version, and if possible try to make it using `2.15`. According to this [wiki](http://en.wikipedia.org/wiki/GNU_C_Library) `Ubuntu 13.04` has it. – CristiFati Jun 10 '15 at 13:06
  • Yes, that's it @CristiFati. I realized which was the library that had this dependency and I asked the software owner for a version compiled using glibc 2.15. It's all working now! – ecnl Jun 12 '15 at 10:07
  • ecnl or @CristiFati, could one of you write up an answer please? – starball Sep 05 '22 at 02:31
  • @davidfong: Done. – CristiFati Sep 05 '22 at 12:35

1 Answers1

0

Although (because the OS is ancient) it might no longer apply, writing an answer (as @ecnl didn't visit the site in years).

The root cause of this is that between the 2 versions, clock_* functions were moved from LibRT to LibC (as pointed out by [SO]: C++ error: undefined reference to 'clock_gettime' and 'clock_settime' (@P.P's answer) (and referenced [SourceWare]: Move clock_* symbols from librt to libc.)).
As a consequence, an ELF linking to v2.17 will not run on v2.15, as it expects those functions to be exported by LibC. Possible fixes:

  1. Rebuild the .so with v2.15 (option already took by OP)

  2. Upgrade LibC to v2.17. However that might trigger some incompatibility issues (other stuff depending on v2.15 might stop working), so this has to be carefully considered

CristiFati
  • 38,250
  • 9
  • 50
  • 87