I will start with the fact that I am no compilation expert. I am trying to compile some c code that I have which utilizes libcurl (among other libraries), and I want it to be as cross-platform for Linux as possible. I am using Ubuntu 22.04.1 x86_x64 Desktop. I have tried using alpine docker as well, with a similar failed result. I will share my steps that I've tried for Ubuntu:
First, I updated my machine: sudo apt-get update
. I then downloaded musl. I used sudo apt-get install musl-tools && sudo apt-get install musl-dev
. There are other dependencies such as git that are needed for the cloning, but I am trying to stick mostly to what I have for musl with these commands.
I then git cloned openssl (version 3.3.0). Although it took some doing, I think I did manage to get openssl statically compiled: file /musl/bin/openssl leads to output of /musl/bin/openssl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped; ldd /musl/bin/openssl leads to output of: not a dynamic executable
. I next tried to do the same process for libcurl, git cloning curl-8.6.0 from https://github.com/curl/curl (I stuck to the master branch). I then ran the following steps:
./configure --prefix=/musl --with-ssl=/musl --without-libpsl --enable-static --disable-shared --disable-dependency-tracking LDFLAGS="-L/musl/lib64 -static -static-libgcc" CPPFLAGS="-I/musl/include" LIBS="-ldl -lpthread -lcrypto"
(I tried to include -lssl but this gave more errors so I tried to leave it out).make && make install
(on regular ubuntu I used sudo, not so on the docker build, since I was writing to /musl and didn't feel like changing the path owner).
The build seems to complete, but when I check whether /musl/bin/curl is statically linked with the file command, I have these results:/musl/bin/curl: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped
and with ldd:/musl/bin/curl: error while loading shared libraries: /lib/x86_64-linux-gnu/libc.so: invalid ELF header
Has anyone managaed to get a successfully statically compiled version of libcurl with musl/musl-gcc? Alternatively, if people have other favorite static compilers that they recommend for ubuntu builds I will take what I can get, my end binary compilation usually includes -lcrypto and -lcurl. Thank you for your help in advance, I will try to answer any questions promptly.