My company servers are running a really old Linux (kernel rev 2.6.32).
On my machine, I installed ocaml-variants.4.10.0+musl+static+flambda, configure dune with the -ccopt and -static flags. However when I copy the exe to the company server, I still get this message:
./lwtTest.exe: /lib/ld-musl-x86_64.so.1: bad ELF interpreter: No such file or directory
Also, I can’t modify server settings, and I did try to set the LD_LIBRARY_PATH to my home folder with the lib being there.
Is there anything else I haven’t tried? Executables built by rust-musl are running just fine, but I prefer OCaml.
It looks like your resulting executable is not actually statically linked to the musl libc. You can check by running ldd <executable>, which should print not a dynamic executable.
For reference, I’m using the following lines in my dune files to create statically compiled executables:
I tend to build the executables in an Alpine docker if I want to be very certain it is statically linked, mostly because I think -static flag have failed me before, but I might have also misremembered.
Possibly the executable format is what’s wrong rather than whether it’s statically linked or not. A given system supports some finite number of executable formats. ELF is such a format, and it looks like your system isn’t set up to execute them.
I think I understand what’s happening. This exe is statically linked with everything except for ld-musl-x86_64.so. There needs to be a musl-x86_64.a static lib, but I don’t seem to find it.
Update: the static lib actually exists: /usr/local/musl/lib/libc.a
How do I tell ocaml.opt to link against it as opposed to ld-musl-x86_64.so.1 ?
And you centos probably provides the already mentioned interpreter. Does your target system provide the interpreter as well, or any other musl interpreter that you might try to change it to using tools like patchelf?
It took a while to get back to that issue. But you were right, patchelf did the trick.
patchelf lwtTest --set-interpreter ./libc.so (this is the musl libc of course).