# Compile a static binary for deployment on cluster

**URL:** <https://internals.rust-lang.org/t/compile-a-static-binary-for-deployment-on-cluster/3353>\
**Category:** cargo\
**Created:** [April 8, 2016, 4:07pm UTC](https://internals.rust-lang.org/t/compile-a-static-binary-for-deployment-on-cluster/3353 "2016-04-08T16:07:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dns2utf8](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dns2utf8/32/1713_2.png) [@dns2utf8](https://internals.rust-lang.org/u/dns2utf8)\
**Post date:** [April 8, 2016, 4:07pm UTC](https://internals.rust-lang.org/t/compile-a-static-binary-for-deployment-on-cluster/3353/1 "2016-04-08T16:07:24Z")

</div>

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:

```rust
/lib64/libc.so.6: version `GLIBC_2.18' not found

```

and the libc on the cluster ist `/lib64/libc.so.6 -> libc-2.17.so`

Regards dns2utf8

---

<div class="post-metadata">

**Author:** ![sfackler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sfackler/32/9_2.png) [@sfackler](https://internals.rust-lang.org/u/sfackler)\
**Post date:** [April 8, 2016, 4:23pm UTC](https://internals.rust-lang.org/t/compile-a-static-binary-for-deployment-on-cluster/3353/2 "2016-04-08T16:23:45Z")

</div>

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](http://www.musl-libc.org/) 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](https://static.rust-lang.org/dist/rust-std-1.7.0-x86_64-unknown-linux-musl.tar.gz)) and then specify that target when you build: `cargo build --target x86_64-unknown-linux-musl`. I haven’t actually tried this myself, though.

---

<div class="post-metadata">

**Author:** ![dns2utf8](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dns2utf8/32/1713_2.png) [@dns2utf8](https://internals.rust-lang.org/u/dns2utf8)\
**Post date:** [May 8, 2016, 12:35pm UTC](https://internals.rust-lang.org/t/compile-a-static-binary-for-deployment-on-cluster/3353/3 "2016-05-08T12:35:55Z")

</div>

Thank you for the hint, I made a docker container for my programm and a [Makefile](https://github.com/dns2utf8/lasttest/blob/master/Makefile) for the command.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:26am UTC](https://internals.rust-lang.org/t/compile-a-static-binary-for-deployment-on-cluster/3353/4 "2019-03-25T08:26:02Z")

</div>

Closed on March 25, 2019, 8:26am UTC

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