Search code examples
d

How to compile static binary?


DMD 2.60 on Ubuntu 12.04 ... I want to create a static binary, so that I can run it in an ages old environment. dmd doesn't have '-static' flag. I tried passing '-static' flag to the linker with "dmd -L-static ..." - get error message

/usr/bin/ld: cannot find -lgcc_s

Compiling C code with "gcc -static ..." works fine. Is it something I miss ? Thanks !


Solution

  • It doesn't currently work if you use dmd to link due to how it passes the linker flags to the linker. You need to build everything with -c to generate object files and then link those manually with either gcc or ld.

    I should point out though that in general, statically linking glibc is considered to be a bad idea. It may very well work and be the correct solution in your case, but it definitely has potential issues (I don't remember the details though). So, you probably shouldn't do it unless you actually need to.