3 ms·
> simpler if you value your time at 0 Or read this blog post once, learning three options to run a binary with non-default glibc: # Set dynamic loader versi
by walterbell 2y ago
> simpler if you value your time at 0
Or read this blog post once, learning three options to run a binary with non-default glibc:
# Set dynamic loader version at link time
cc -o hello_c -Wl,--dynamic-linker=/tmp/sysroot/lib/ld-linux-x86-64.so.2 hello.c
# Set dynamic loader version at run time
/tmp/sysroot/lib/ld-linux-x86-64.so.2 ./hello_c
# Edit dynamic loader version in binary
patchelf --set-interpreter /tmp/sysroot/lib/ld-linux-x86-64.so.2 ./hello_c
- 01HNNWZ0MV43FF 2y agoI have never needed to call `patchelf` for anything. If I saw someone putting `--dynamic-linker` in a call to a C compiler I would assume it's out of scope for me. There's already like 100 tools I need to know for my job, I don't want low-level OS and C stuff to add another 50 or even another 20. This is a little bit "Whatever the world was like when I was 20 is perfect, everything before that is too old, everything after that is too new", but, I'm definitely just reaching for Docker for this. Unless I'm running a GUI application or something else that's hard to containerize.
- walterbell 2y agoOne-line instant alternative to OS/VM/container install. Either path can be chosen.
- theamk 2y agoYou'll want to carefully re-read the text, it's not one line. Where do you think all those libraries come from? And for anything more complex than "hello world", how did we know which libraries to include? Once you solve those two, your thing will be more lines of code than most Dockerfiles.
- AlotOfReading 2y agoIt's 3 different one-liners that all accomplish the same goal. The binary itself will tell you what libraries are needed, so I don't get your objections here.
- kelnos 2y agoTo be fair, it's not one line: before getting to use that one line, have to build a whole other glibc as well. Which is often not a particularly fun process.
- kelnos 2y agoIt's kinda funny because you sorta fall into the same trap you accuse the GP of. Your "Whatever the world was like when I was 20..." quote kinda boils down to "I am fine with the tools I already know how to use and, and I don't want to learn something new". And then you say... you already have your 100 tools and don't want to learn any others. Same deal, really.
- theamk 2y agoThis depends on your goal. If you are designing the program yourself, you can use this trick to make your distribution more portable. You'll have to configure linker to change RPATH as well, and modify your packaging scripts to also grab any .so files associated with it, like libm, libpthread, librt and so on. You'll also want to make sure no library uses hardcoded data/configs with incompatible settings (like /etc/nsswitch.conf). No public Linux will ever accept this, but it would be a reasonable way to distribute your internal app to your non-homogeneous linux fleet. For complex third-party apps, it's going to be harder - you'll want some sort of dependency collector script that follows both load-time and run-time loading; you'll also want to do something about data and config files. If there are hardcoded paths (like Python or gcc), you will have to do something about them too. That will be basically a custom, non-trivial effort for each program. Definitely possible, but also much more complex than sticking some "apt install" in Dockerfile.
- WhyNotHugo 2y agoIf you want your binary to be compatible with heterogeneous distributions, it’s best to statically link a different libc instead.
- myworkinisgood 2y agoworkflows are calling you out. At max, the workflow might be able to do `2` but that's also a big may be.