curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: static cURL

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Tue, 10 Oct 2017 07:24:19 +0200

On Tue, Oct 10, 2017 at 12:18:25AM +0200, Laura Martín via curl-users wrote:
> I'm trying to compile a completely static curl binary but I get glibc and
> others shared:

Just to get the obvious out of the way, do you have the static libc.a
available to link against?

> ldd /opt/curl_Static/bin/curl
>     linux-vdso.so.1 (0x00007ffc0a5cf000)
>     libdl.so.2 => /lib64/libdl.so.2 (0x00007f60ff491000)
>     libc.so.6 => /lib64/libc.so.6 (0x00007f60ff0f8000)
>     /lib64/ld-linux-x86-64.so.2 (0x00007f60ff695000)
>
>
> My config stanza:
>
> CPPFLAGS="-I/usr/include" CFLAGS="-static" LDFLAGS="-L/lib64 -static" LIBS=
> "-ldl -lssl -lcrypto" ./configure --prefix=/opt/curl_Static --disable-shared
> --enable-static --disable-threaded-resolver --with-ssl=/opt/openssl_Static/

Note that you're generally better off using pkg-config to pick up other
libraries, rather than passing directories in the flag arguments, so set
PKG_CONFIG_PATH here appropriately here instead.

> --with-tls --with-zlib=/opt/zlib_Static/
>
> I need a completely static curl, because the final servers are very old and
> don't have modern versions of glibc and openssl.
>
> Is it possible or have I to compile statically all the environment (gcc,
> glibc...)

I've found that libtool strips off -static if it can't statically link against
any one of the dependent libraries. Try building with 'make V=1' and add
-static to the final gcc link command line to see what errors it gives you.
It could be looking for a static library that isn't there.

Note that it's hard/impossible to completely statically link against glibc.
IIRC, some features are just not available when statically linked and must have
dynamic libraries available. If you want to statically link, uClibc or
MUSL are better choices.

>>> Dan
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-10-10