Portable binary with musl
See original GitHub issueHello! Thank you for Nuitka!
Could you please advice what is the best way to make standalone binary with portable musl wich will work portable on Ubuntu and Alpine? I tried and looks like close to success.
Here is the example and additional questions below:
- I build the xxh project (it hasn’t any complex libs) with Nuitka:
docker run --rm -it -v `pwd`:/host alpine sh
apk add --update musl-dev gcc python3-dev py3-pip chrpath git vim mc
pip3 install -U "https://github.com/Nuitka/Nuitka/archive/factory.zip"
pip3 install pexpect pyyaml
git clone --depth 1 https://github.com/xxh/xxh
cd xxh
nuitka3 --python-flag=no_site --python-flag=no_warnings \
--show-progress --standalone --follow-imports xxh
- After it I have
xxh.dist
withldd xxh
on Alpine:
/lib/ld-musl-x86_64.so.1 (0x7f58f86fb000)
libpython3.8.so.1.0 => ./libpython3.8.so.1.0 (0x7f58f7a96000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f58f86fb000)
The app works perfect on Alpine.
- Then I move it to Ubuntu and I’ve got
ldd xxh
:
linux-vdso.so.1 (0x00007ffeeedd9000)
libpython3.8.so.1.0 => /home/pc/xxh/xxh/xxh.dist/./libpython3.8.so.1.0 (0x00007efd2813c000)
libc.musl-x86_64.so.1 => not found
libc.musl-x86_64.so.1 => not found
- When I copy
libc.musl-x86_64.so.1
from Alpine toxxh.dist
I’ve gotldd xxh
on Ubuntu:
linux-vdso.so.1 (0x00007ffce37ac000)
libpython3.8.so.1.0 => /home/pc/xxh/xxh/xxh.dist/./libpython3.8.so.1.0 (0x00007fbbf0df5000)
libc.musl-x86_64.so.1 => /home/pc/xxh/xxh/xxh.dist/./libc.musl-x86_64.so.1 (0x00007fbbf0d5f000)
- Looks good, but not working:
ubuntu$ ./xxh
bash: ./xxh: No such file or directory
- And only if I copy
musl
to/lib
on Ubuntu I have success:
$ sudo cp libc.musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
$ ./xxh -V
0.6.0
- If I open
xxh
binary in vim I see absolute path/lib/ld-musl-x86_64.so.1
and it looks like the cause why I should copy the musl to system lib directory.
A. Please advice what I can do to make musl portable with the app?
B. Is there a way to statically compile musl inside the app?
C. Is there a way to make one big static binary xxh
file?
Musl is small and some projects use it instead of libc for creating static standalone apps. It will be great if Nuitka can do the same.
Many thanks to your work!
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Getting started - musl libc
Whether building your own or downloading binaries, you need to select the appropriate GCC-style tuple for the architecture/ABI you want to target. It...
Read more >84.0.4147.135-1.musl1: Binaries for Portable Linux 64-bit (for ...
84.0.4147.135-1.musl1: Binaries for Portable Linux 64-bit (for musl libc) · Release Information · Downloads.
Read more >How to create portable Linux binaries (even if you need a ...
Yep, I just use musl libc and static link everything into the binary. Simpler than all the effort here to use a libc...
Read more >Build portable linux binaries without using an ancient distro
If we want to make truly static binaries that will run no matter how old the system glibc we use the musl c...
Read more >porting to musl (was: building static binaries / reducing library ...
At the source level, it would be nice to standardize a portable POSIX module, though that of course is a fairly involved project....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve got success!
This error means that on line 8 in Python standard
datetime.py
file there is an import of module which not included to Python static while building.To fix this:
datetime.py
(/usr/lib/python3.8/datetime.py
on Alpine) and get the module name from line 8 (it’smath
module)Python3.8.2/Modules/Setup
, search the module and uncomment:/usr/lib
:Next steps. I’ve built static python as described in wiki and got
libpython3.8.a
.Next I tried to static build with
LDFLAGS
:After this I’ve got
xxh.dist
withldd xxh
:And on Ubuntu
ldd shows
:It’s much better than before!
But when I tried to run
./xxh
I’ve got: