0

I am trying to compile a C program while linking dynamically libcurl and statically libc.

My Makefile looks like:

SRC=myprogram.c

LDFLAGS+= -static libc.a -static-libgcc -Wl,-static -lc

LDFLAGS+= -linfluxdb -lcurl -lm -ljson-c

I need to link libc dynamically because libc version is not the same between centos7 and centos6, so I will include the chosen one in the binary. I could have linking everything statically but it's not working for libcurl; I am having errors in the linker resolving several libcurl functions. I tried to add "dynamic" flag for libcurl

LDFLAGS+= -Wl,-Bdynamic -lcurl

But I still have a dynamic reference to libc. Ldd outputs:

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff3811b2000)

Through this question (Static linking libcurl using c) I knew that libcurl depends on libc. Is it a way to force the usage of static libc everywhere ?

Community
  • 1
  • 1
  • 1
    You'd have to use a libcurl build that statically links libc also. But are you sure you need to? Have you tried linking dynamically with the newer libc and running with the older one? If I remember, glibc is supposed to have a large degree of both forward and backward compatibility, so long as you don't rely on features that are missing from the older version. Regardless, you'll probably be fine if you link (dynamically even) against the older libc. – Dmitri Oct 05 '15 at 17:23
  • Just link everything dynamically on the older system. – n. m. could be an AI Oct 05 '15 at 17:38
  • @Dmitri when compiling on centos7, the dynamically linked libc cannot be resolved on centos6 when installing the rpm. The centos7 version is not compatible with centos7 version. – Radhwane Chebaane Oct 06 '15 at 09:02
  • @n.m. : Linking everything on the older system would be a better solution if all the build tools are available. In fact, the old system (centos6) has deprecated versions of build tool not enough for building the project (autoconf, configure...). – Radhwane Chebaane Oct 06 '15 at 09:05
  • You can build on the new system but compile/link against the old system headers/libraries. You can also install a newer local version of build tools on an old system (build them from source). Finally you can build on a clean new system but explicitly specify symbol versions that are compatible with older symbols (see e.g. http://stackoverflow.com/questions/2856438/how-can-i-link-to-a-specific-glibc-version). – n. m. could be an AI Oct 06 '15 at 09:54

0 Answers0