Friday, September 6, 2013

Make binaries static

This is the second time I need a static compiled executable and of course I forgot how to do it. Actually it is really easy just add "-static" to your build process. The tricky part is where to put it. Some configuration scripts provide a "--enable-static" or "--disable-shared" but this is rarely the case. So if you have some source first configure it as usual (autogen,configure,...) after that edit the Makefile and "-static" to the CFLAGS. That should do the trick. Following block is from emacs 24.3 lib-src Makefile to get a static linked emacsclient.

EMACS = ../src/emacs
EMACSOPT = -batch --no-site-file --no-site-lisp
# ==================== Things `configure' will edit ====================
CC=gcc -std=gnu99
CFLAGS=-g3 -O2 -static
version=24.3
## Used in $archlibdir.
configuration=x86_64-unknown-linux-gnu
EXEEXT=
C_SWITCH_SYSTEM=

No comments:

Post a Comment