Statically building when curl is present

John Goerzen <[email protected]> Thu, 15 Jun 2023 08:09:04 -0500
Newsgroups gmane.comp.sysutils.backup.dar.support
Message-ID <[email protected]>
Hi Denis,

I'm the new Debian maintainer for dar.  I got libthreadar accepted into
Debian, so now I am working to enable the full remote featureset
including curl support.

I am running into difficulties with dar_static.  Particularly, it looks
like dar_static is trying to link with curl, and this is problematic.

I get these messages:

/bin/bash ../../libtool  --tag=CXX   --mode=link g++  -g -O2 -ffile-prefix-map=/home/jgoerzen/work/dar=. -fstack-protector-strong -Wformat
-Werror=format-security -all-static  -Wl,-z,relro -Wl,-z,now -o dar_static command_line.o config_file.o dar.o dar_suite.o hide_file.o no_co
mment.o line_tools.o crit_action_cmd_line.o ../libdar/libdar64.la -lcurl  -L/usr/lib/x86_64-linux-gnu -lgpgme -lassuan -lthreadar -lpthread
   -largon2 -lpthread -lrsync -lgcrypt -lgpg-error -llz4 -lzstd -llzma -llzo2 -lbz2 -lz -ldl -lcap
libtool: link: g++ -g -O2 -ffile-prefix-map=/home/jgoerzen/work/dar=. -fstack-protector-strong -Wformat -Werror=format-security -static -Wl
,-z -Wl,relro -Wl,-z -Wl,now -o dar_static command_line.o config_file.o dar.o dar_suite.o hide_file.o no_comment.o line_tools.o crit_action
_cmd_line.o  ../libdar/.libs/libdar64.a -lcurl -L/usr/lib/x86_64-linux-gnu -lgpgme -lassuan -lthreadar -largon2 -lpthread -lrsync -lgcrypt
-lgpg-error -llz4 -lzstd -llzma -llzo2 -lbz2 -lz -ldl -lcap
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libgpg-error.a(libgpg_error_la-sysutils.o): in function `_gpgrt_getpwdir':
(.text+0x2ca): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version
used for linking
/usr/bin/ld: (.text+0x2e8): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the g
libc version used for linking
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcurl.a(libcurl_la-netrc.o): in function `Curl_parsenetrc':
(.text+0x79c): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcurl.a(libcurl_la-curl_addrinfo.o): in function `Curl_getaddrinfo_ex':
(.text+0x6f): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcurl.a(libcurl_la-psl.o): in function `Curl_psl_destroy':
(.text+0x21): undefined reference to `psl_free'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcurl.a(libcurl_la-psl.o): in function `Curl_psl_use':
(.text+0xbc): undefined reference to `psl_latest'
/usr/bin/ld: (.text+0x157): undefined reference to `psl_builtin'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcurl.a(libcurl_la-version.o): in function `curl_version':
(.text+0x129): undefined reference to `BrotliDecoderVersion'


... and this goes on for pages and pages.

Investigating a bit, I see there's a curl-config command.  I note the
difference:

jgoerzen@hephaestus:~/work/dar$ curl-config --static-libs
-Wl,-Bstatic -lcurl -Wl,-Bdynamic -lnghttp2 -lidn2 -lrtmp -lssh2 -lssh2 -lpsl -lssl -lcrypto -lssl -lcrypto -lgssapi_krb5 -llber -lldap -llber -lzstd -lbrotlidec -lz
jgoerzen@hephaestus:~/work/dar$ curl-config --libs
-lcurl

The static .a files won't automatically pull in their dependencies.
However, I can't just add `curl-config --static-libs` to the g++ call
because everything after the -Wl,-Bdynamic will cause an error.
Removing the -Wl,-Bdynamic, and installing a bunch of other dev packages
gets close, but:

jgoerzen@sid:~/work/dar/src/dar_suite$ g++ -g -O2 -ffile-prefix-map=/home/jgoerzen/work/dar=. -fstack-protector-strong -Wformat -Werror=format-security -static -Wl,-z -Wl,relro -Wl,-z -Wl,now -o dar_static command_line.o config_file.o dar.o dar_suite.o hide_file.o no_comment.o line_tools.o crit_action_cmd_line.o  ../libdar/.libs/libdar64.a -lcurl -L/usr/lib/x86_64-linux-gnu -lgpgme -lassuan -lthreadar -largon2 -lpthread -lrsync -lgcrypt -lgpg-error -llz4 -lzstd -llzma -llzo2 -lbz2 -lz -ldl -lcap -lssl -lcrypto -lnghttp2 -lidn2 -lrtmp -lssh2 -lssh2 -lpsl -lssl -lcrypto -lssl -lcrypto -lgssapi_krb5 -llber -lldap -llber -lzstd -lbrotlidec
/usr/bin/ld: cannot find -lgssapi_krb5: No such file or directory
collect2: error: ld returned 1 exit status

And here I run into a problem because libgssapi_krb5 is not available in
a static (.a) version.

I have a question at this point: how did others manage to get this to
build statically with curl?  My best guess is that maybe they're on
platforms where curl itself was compiled with fewer features.

I'm also concerned about the warnings about requiring shared libraries
for getpwnam() and such.

Anyhow, then the question becomes: how to resolve this?

As far as I can tell, the only solution is to not link dar_static with
curl.  I don't see that option in configure, though; it's all or
nothing with that one.

BTW on a totally different topic, just wanted to verify you saw
https://github.com/Edrusb/DAR/issues/50

Thanks!

- John