GDB 8.3.1 gdbserver linker error: needs -lrt

Simon Marchi simark@simark.ca
Thu Jan 30 21:35:00 GMT 2020


On 2020-01-30 4:23 p.m., Paul Smith wrote:
> 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 libinproctrace.so 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: libinproctrace.so 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...
> 

GDBSERVER_LIBS is a variable in gdb/gdbserver/Makefile, but I don't think
it's meant to be overriden from the command line.  It's just an internal
variable to simplify the Makefile, as well as an autoconf variable (not sure
if that's the right term) that gets replaced in Makefile.in.

It would probably work to set LIBS while configuring gdbserver:

  ./configure LIBS="-lrt"

That would work around the problem, but if you want to fix it for good, for all
users in the same situation, then it would probably require a patch to configure.ac,
to add "-lrt" to LIBS when needed.

Simon



More information about the Gdb mailing list