GDB 8.3.1 gdbserver linker error: needs -lrt

Paul Smith
Thu Jan 30 21:23:00 GMT 2020

Hi all;

I was trying to compile the latest GDB for my system and the link of
gdbserver failed:

.../lib64/libstdc++.a(chrono.o):function std::chrono::_V2::system_clock::now(): error: undefined reference to 'clock_gettime'
.../lib64/libstdc++.a(chrono.o):function std::chrono::_V2::steady_clock::now(): error: undefined reference to 'clock_gettime'

As you can see I compile with static libstdc++.  Also, I'm building
against a pretty old version of GNU/Linux with an older GNU libc
(CentOS 6.5 or so).

The problem is that on systems this old you need to add -lrt to the
link line in order to get clock_gettime(), and the configure script
doesn't look for this.

This causes both gdbserver and to fail to link,
unless I hack the makefiles.

Gdb itself links properly because I'm linking with lzma and those libs
happen to include -lrt:

  LIBLZMA = .../lib/liblzma.a -lrt

Oddly enough, adding GDBSERVER_LIBS="-ldl -lrt" to the top GDB make
command doesn't work (even for gdbserver: has no
equivalent customizable library). I didn't look through the build
system to figure out how my command line overrides are being lost but
that's also something that should be fixed...

More information about the Gdb mailing list