How to generate a Linux static build of a binary

Last week to contribute to the SteamTinkerLaunch in order to improve the SteamDeck integration I did various pull requests and joined various tickets.

One of the point was Yad that is a GTK tool to generate UI from bash, STL it is based on this project.
I saw that the Yad version it wasn’t updated and it was an appimage.

I said to myself, well I don’t like those stuff and I have no idea how works, maybe I can generate a static build of Yad so STL it is more simple.

I discovered the packelf project from an interesting StackOverflow discussion of the same topic.

How to do a static build

As Linux user we know that usually a binary can be self contained with all the dependencies built in, like for SaaS clients that are heavy with all the libraries.
Or usually is just the binary and requires that you have installed the various dependencies.

Another solution is to get a binary and get all the libraries in the system you are running it and package it.

Honestly initially I thought like the SO comment, use ldd to generate the list of the library used by the binary and somehow run with them in another amd64 system.

Using a command like $ LD_LIBRARY_PATH="/opt/my_program/lib" /opt/my_program/start it should be possible but a script is more faster as there are tons of dependencies to find. is a way to automatize the finding of the libraries, package in a executable tar and run a bash script that preload all of them.

In my experimenting I did a fork with another script that instead keep the folder, as the script extract on the /tmp folder (it is quite fast in this way indeed) but everytime the process closed the folder is removed.

I tested it and works, even on a different system like ArchLinux compared to my Debian.

The Yad example

Following this experiments locally, it was time to automatize them.
Another repository it was created with a GitHub CI that automatically on a new release/tag compile it and attach to the release itself the binary in a zip.

You can download Yad from the releases and check the CI that put everything together.

The version without HTML support was 13mb zipped and 200mb extracted, and the packaged version with HTML support is 70mb (I don’t remember when extracted).
As far I can see right now Yad works, but the webkitgtk part doesn’t, so if you have any ideas to help me you are welcome.

Probably it wasn’t clear, but we are talking about amd64 architecture, as a different one will not work. So if you run the script on arm, the binary will be only for arm, etc.


At the end, STL project will still use appImage, so we will see how to proceed on that path.

It was a nice experimenting that let’s to learn how libraries works on Linux.

Off course this is not something bulletproof but is something that can be handy in various cases.
As I used also PyInstaller in a CI, I think that this project does the same thing for python script builds.

Liked it? Take a second to support Mte90 on Patreon!
Become a patron at Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *