Compile a static binary for deployment on cluster

Hi all

I would like to deploy my working binary on the cluster. Currently I hit the problem, of different locations of libc, and I am using cargo for the addons.

Is it possible to tell cargo to generate a static binary? It is ok if it becomes a big one.

The error I get from the binary is:

/lib64/ version `GLIBC_2.18' not found

and the libc on the cluster ist /lib64/ ->

Regards dns2utf8

The issue isn’t exactly the location of libc, but rather the version of libc that the binary requires. There are a couple of approaches here.

You can compile your binary on a system with a sufficiently old version of libc - I like to use Docker for this personally.

It’s unfortunately not really possible to statically link to glibc in a reasonable way. If you do want a completely static binary, another option is to use the x86_64-unknown-linux-musl target, which uses musl as its libc instead of glibc and can be statically linked. I believe all you’ll have to do in this case is install musl, install a copy of the standard library built for that target (available here) and then specify that target when you build: cargo build --target x86_64-unknown-linux-musl. I haven’t actually tried this myself, though.

1 Like

Thank you for the hint, I made a docker container for my programm and a Makefile for the command.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.