Running it on an older Debian system I get
./hello: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by ./hello)
The resulting binary runs fine on the older Debian system.
I thought that some sort of static linking took place. However, it is not quite clear to me what happened as ldd shows basically the same for both hello binaries.
If I want a nim-created executable to run on older systems does "--opt:size" all the magic?
You might be right that I was just lucky.
It seems when having installed musl using it would be the easiert solution. How would I use musl with nim?
Stefan, thanks for the pointer. Great article.
Worked fine to build a static binary which is even smaller than the standard binary.
Ok, creating a static binary works like this for hello.nim
nim --gcc.exe:/usr/bin/musl-gcc --gcc.linkerexe:/usr/bin/musl-gcc -d:release --opt:size --passL:-static --out:hello.static c hello.nim
Now trying hello_nre.nim
import nre
echo "1 2 3 4 5 6 ".split(re" ")
creating the static binary as above.
Running it gives:
could not load: libpcre.so(.3|.1|)
Anybody in the knowing how to tell nim to take the pcre static library (I installed the static pcre library)?
Have you tried -passL with name of pcre lib as in this thread:
but got gcc: error: libpcre.a: No such file or directory
I had a similar problem compiling a static binary on an Alpine Linux Docker image.
I got around it by:
--define: usePcreHeader
and also:
--passL: "/usr/lib/libpcre.a"
For GNU/Linux system, I have created this config.nims to statically link pcre using musl. See https://github.com/kaushalmodi/hello_musl.
Clone it (on a GNU/Linux system with musl-gcc installed) and simply run nim musl -d:pcre src/hello_musl_pcre.nim.