# Build a crystal program statically

**URL:** <https://forum.crystal-lang.org/t/build-a-crystal-program-statically/5215>\
**Category:** Help & Support\
**Created:** [December 29, 2022, 10:40pm UTC](https://forum.crystal-lang.org/t/build-a-crystal-program-statically/5215 "2022-12-29T22:40:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [December 29, 2022, 10:40pm UTC](https://forum.crystal-lang.org/t/build-a-crystal-program-statically/5215/1 "2022-12-29T22:40:21Z")

</div>

Hello, today for a special need, I need to build my crystal program statically.

But I have this error, and I don’t know how to fix it.

I have this error in my manjaro virtual machine:

```auto
    ~/ism1    master !2 ?5  crystal build Main.cr --static -o ism  ✔ 
/usr/bin/ld: cannot find -lgc (this usually means you need to install the development package for libgc): No such file or directory
/usr/bin/ld: cannot find -levent (this usually means you need to install the development package for libevent): No such file or directory
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o /home/zohran/ism1/ism -rdynamic -static -L/usr/bin/../lib/crystal -lm -lgc -lpthread -levent -lrt -lpthread -ldl`

```

The problem is, there isn’t any dev package for that, or I didn’t found it.

I have a similar error on my main system, gentoo:

```auto
zohran@alienware-m17-r3 ~/Documents/Programmation/ISM $ crystal build Main.cr --static -o ism
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lpcre (this usually means you need to install the development package for libpcre): No such file or directory
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o /home/zohran/Documents/Programmation/ISM/ism -rdynamic -static -L/usr/bin/../lib/crystal -lpcre -lm -lgc -lpthread -levent -lrt -lpthread -ldl`
[ble: exit 1]

```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [December 30, 2022, 3:12am UTC](https://forum.crystal-lang.org/t/build-a-crystal-program-statically/5215/2 "2022-12-30T03:12:36Z")

</div>

See [Static Linking - Crystal](https://crystal-lang.org/reference/1.6/guides/static_linking.html#fully-static-linking).

tl;dr the easiest way to is use alpine linux via docker as it uses musl libc which plays better with static linking.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [December 30, 2022, 10:20am UTC](https://forum.crystal-lang.org/t/build-a-crystal-program-statically/5215/3 "2022-12-30T10:20:59Z")

</div>

Check my github action for how build static for linux and for mac.

> **[Actions · crystal-china/procodile\_cr](https://github.com/crystal-china/procodile_cr/actions)**
>
> 🐊 Run processes in the background (and foreground) on Mac & Linux from a Procfile (for production and/or development environments) - Actions · crystal-china/procodile\_cr

---

<div class="post-metadata">

**Author:** ![Xen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/xen/32/2288_2.png) [@Xen](https://forum.crystal-lang.org/u/Xen)\
**Post date:** [January 4, 2023, 8:38pm UTC](https://forum.crystal-lang.org/t/build-a-crystal-program-statically/5215/4 "2023-01-04T20:38:03Z")

</div>

@zw963 Oh, nice… Have you considered making it a public action like [GitHub - goreleaser/goreleaser-action: GitHub Action for GoReleaser](https://github.com/goreleaser/goreleaser-action)?
