question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create one portable statically linked executable file using Nuitka

See original GitHub issue

Hi! Thank you for Nuitka!

For xxh project (console tool) I created one portable statically linked executable file using Nuitka:

https://github.com/xxh/xxh-portable/blob/e26e48985621a33cde32772d672f11c3b3843f16/xxh-portable-musl-alpine.Dockerfile#L16-L28

As you can see I build the Python library first (libpython3.8.a with appropriate modules) and then use it in LDFLAGS before running Nuitka. I did this in Alpine with musl and as result I get the one portable statically linked ./xxh binary file that could be run on many Linux distributes.

Is there a way now or future feature to do this in Nuitka by one command and by using one option i.e. --standalone-static?

Thanks!

For community: ⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
emsicommented, Jul 14, 2021

--onefile does not produce statically linked executable. When moved to another system it tries to use host’s glibc. My guess it’s AppImage?

$ file python_app.bin 
ludo.bin: ELF 64-bit LSB executable, x86-64, version 1, dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, stripped


$ ./python_app.bin 
./ludo.bin: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ./ludo.bin)
./ludo.bin: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /tmp/.mount_ludo.bcgjdNl/libpython3.8.so.1.0)
./ludo.bin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /tmp/.mount_ludo.bcgjdNl/libpython3.8.so.1.0)
./ludo.bin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /tmp/.mount_ludo.bcgjdNl/libpython3.8.so.1.0)
./ludo.bin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.26' not found (required by /tmp/.mount_ludo.bcgjdNl/libpython3.8.so.1.0)
./ludo.bin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.27' not found (required by /tmp/.mount_ludo.bcgjdNl/libpython3.8.so.1.0)
./ludo.bin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /tmp/.mount_ludo.bcgjdNl/libexpat.so.1)

Having an option to build truly statically linked binary would be great for producing portable applications.

1reaction
kayhayencommented, Jul 14, 2021

There is a hacky way to enable non-appimage, using --onefile-tempdir, which is undocumented, and enables the code used on macOS, FreeBSD, etc. and actually I didn’t consider static linking of glibc for libc for those, as they won’t have the issue.

For commercial users, there is a Linux container with old glibc and new tools chain, that you build these in, and then they ought to be portable:

https://nuitka.net/pages/commercial.html

I think Nuitka creates binaries dynamically linked by default, and chances are that Python you are using does it as well. The only way to produce forward working binaries, is to do it on the oldest system you want to support. On Linux, things are not really geared well for backward porting of binaries.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Create one portable statically linked executable file ...
Create one portable statically linked executable file using Nuitka. ... Coming soon: A brand new website interface for an even better experience!
Read more >
User Manual - Nuitka
No information is available for this page.
Read more >
PyOxidizer 0.8 - Hacker News
On Linux, PyOxidizer can produce executables that are fully statically linked and don't even support dynamic loading.
Read more >
Can I create single file executable with nuitka? - Stack Overflow
I tried --portable and --standalone option but they does not seem to work. And can anyone please explain me what is the --recurse-all...
Read more >
Nuitka · PyPI
Nuitka translates the Python modules into a C level program that then uses libpython and static C files of its own to execute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found