curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Static binary of curl including libssh2 for sftp/scp support

From: toby via curl-users <curl-users_at_cool.haxx.se>
Date: Thu, 15 Aug 2019 15:50:21 -0600

i don't think you can build a real static curl - you can do it for external libs but still needs glibc at runtime for nsswitch ?

---
They said if i help and post this they will knock off time from my community service so here goes :  (just kidding - if you don't count hacking programmers commit 0% of the crime in the world)
---
i worked out a process over the years and this is my current method (and it works on current 7.65.3 release but the above still holds - it isn't a true linux static program - it needs the same glibc as what it was compiled with
i guess you could use LD_LIBRARY_PATH to an alternate glibc install it if it isn't the default one on the new system
--
make sure that you I have the libssh.a and libssh2.and libgcrypt.a  files    (libssh.a isn't needed for sftp though)
make sure the libgcrypt.la file has the following in it     (this caused me problems a while back so i mention it every chance i get - the ladies love it!)
# The name of the static archive.
old_library='libgcrypt.a'
you need to first make a libcurl.a  (libcurl static library)
configure LIBS=-ldl --prefix=/usr/local/curl-static --disable-shared --enable-static --disable-debug --disable-ares --enable-http --enable-ftp --enable-file --disable-ldap --disable-ldaps --enable-rtsp --enable-proxy --enable-dict --disable-telnet --enable-tftp --enable-pop3 --enable-imap --enable-smb --enable-smtp --disable-gopher --enable-manual --enable-libcurl-option --disable-ipv6 --enable-nonblocking --enable-threaded-resolver --enable-verbose --disable-sspi --enable-crypto-auth --disable-ntlm-wb --disable-tls-srp --enable-unix-sockets --with-ssl --without-nss --without-libidn --with-libssh --with-libssh2 --without-libpsl --enable-cookies
make
rm -rf src/curl                   < this curl isn't static
--
now make the static curl and install it in the prefix
make LDFLAGS="-all-static"
you should see a warning about still needing glibc at runtime
/usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x4c): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
strip src/curl            (my 800MB quantum drive fills up fast so i gotta save space where and whenever possible)
make install
ldd /usr/local/curl-static/bin/curl
not a dynamic executable
---
and if you have any problem - just post the exact errors etc     my system is rather unique and 'you might need some slight adjustments to get it to run well' (quote from my car mechanic before he billed me $835)
On Thu, 15 Aug 2019 08:33:33 +0200
Malte Schmidt via curl-users <curl-users_at_cool.haxx.se> wrote:
> Hello,
>
> I am currently trying to build a static curl binary on alpine using musl
> like this:
>
> apk add gcc make musl-dev openssl-dev libssh2-dev
> wget https://curl.haxx.se/download/curl-7.63.0.tar.xz
> tar xvfJ curl-7.63.0.tar.xz
> cd curl-7.63
> ./configure --disable-shared
> make curl_LDFLAGS=-all-static
>
> This results in a static binary but without sftp/scp support, so:
>
> apk add gcc make musl-dev openssl-dev libssh2-dev
> wget https://curl.haxx.se/download/curl-7.63.0.tar.xz
> tar xvfJ curl-7.63.0.tar.xz
> cd curl-7.63
> ./configure --disable-shared --with-libssh2
> make curl_LDFLAGS=-all-static
>
> This automatically compiles a curl binary, which is dynamically linked.
>
> Now, what is the most clean and elegant way of creating a static curl
> binary which includes libssh2 and therefore sftp/scp support?
>
> Thanks in advance and best regards!
>
>
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2019-08-15