libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] '-lrt' not resolving undefined reference to clock_gettim


From: Alex Reynolds
Subject: [libmicrohttpd] '-lrt' not resolving undefined reference to clock_gettime?
Date: Mon, 20 Mar 2017 01:55:08 -0700

I am compiling a static binary ("my_project") that links in a static compilation of the libmicrohttpd.a library, along with a couple other libraries.

On some platforms, this appears to work. 

On others, like a default image of Linux that is used in Travis CI (Ubuntu 12.04.5 LTS, gcc 4.6.3), I get the following compilation error related to libmicrohttpd:

<project>/third-party/libmicrohttpd/lib/libmicrohttpd.a(libmicrohttpd_la-mhd_mono_clock.o): In function `MHD_monotonic_sec_counter_init':
<project>/third-party/libmicrohttpd/src/microhttpd/mhd_mono_clock.c:160: undefined reference to `clock_gettime'
<project>/third-party/libmicrohttpd/src/microhttpd/mhd_mono_clock.c:180: undefined reference to `clock_gettime'
<project>/third-party/libmicrohttpd/src/microhttpd/mhd_mono_clock.c:191: undefined reference to `clock_gettime'
<project>/third-party/libmicrohttpd/src/microhttpd/mhd_mono_clock.c:202: undefined reference to `clock_gettime'
<project>/third-party/libmicrohttpd/lib/libmicrohttpd.a(libmicrohttpd_la-mhd_mono_clock.o): In function `MHD_monotonic_sec_counter':
<project>/third-party/libmicrohttpd/src/microhttpd/mhd_mono_clock.c:315: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [my_project] Error 1

From reading Stack Overflow, this appears to be related to linking the Real Time library (`-lrt`).

I have tried compiling my static binary with the addition of `-Wl,--no-as-needed -lrt` to my LIBS variable, which is positioned in the build statement after the objects are compiled, e.g.:

...
gcc -g -Wall -Wextra -std=c99 -D__USE_POSIX -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O3 -pthread -static -static-libgcc -I/usr/include -I<project>/third-party/bzip2 -I<project>/third-party/libmicrohttpd/include -L"<project>/third-party/bzip2" -L"<project>/third-party/libmicrohttpd/lib" my_project.o -o my_project mt19937.a -Wl,--no-as-needed -lrt -lm -lbz2 -lmicrohttpd
...

However, this patch did not work. I still get the same fatal build errors. 

As the example build statement shows, I can incorporate other static libraries into my project's binary -- just not libmicrohttpd. I'm not sure what else to try and was wondering if others might have ideas.

In Travis CI, I would also get similar errors about undefined references to Pthreads calls, which I fixed by adding `-pthread` to my build flags, as well as undefined references to functions in libgcrypt and GnuTLS libraries, which I fixed by adding `--without-libgcrypt --without-gnutls` to the libmicrohttpd ./configure options. 

Is there a similar modification I can make to my build or linking process to resolve the clock_gettime() call errors, so that I can incorporate the static libmicrohttpd.a library? 

Thanks for any advice!

Regards,
Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]