libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] '-lrt' not resolving undefined reference to clock_ge


From: Christian Grothoff
Subject: Re: [libmicrohttpd] '-lrt' not resolving undefined reference to clock_gettime?
Date: Tue, 21 Mar 2017 13:53:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

glibc < 2.17 requires -lrt for clock_gettime(), older versions do not.
I've added "-lrt" in Git commit ed6509bf6ca46e39e3514680bfb81216e2a825bf
but without testing (as I don't have an ancient glibc on this system and
I am on a train...).  Please let me know if it does not work...

Happy hacking!

Christian

On 03/20/2017 09:55 AM, Alex Reynolds wrote:
> 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
> 
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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