I have a uclibc toolchain that works. I can compile a simple hello.c program statically (arm-linux-gcc hello.c -o hello -static -s) but source packages are automatically compiled dynamically. How can I change the default to static?
1 Answer
You have to edit the makefile of the source packet you are compiling (extra LDFLAG -static, just as you did for the hello.c file). Most of the time source packets are delivered with autoconf. In that case you can probably pass the --enable-static-link flag to configure. See configure --help for the set of possible arguments.
Other note: be careful when cross compiling packages which need other libraries. You do not want to link in your host machine libraries statically.
-
I still get a dynamically linked prog when editing Makefile. Compiling lighttpd with CFLAGS = -g -O2 -Wall -W -Wshadow -pedantic -std=gnu99 -static results in: file src/lighttpd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped. Compiling the joe editor gives the same results.– jocalaOct 10, 2011 at 17:53
-
My bad, you should look for LDFLAGS, which contain the flags for linking and add -static to that.– MichelOct 10, 2011 at 19:23
-
Thanks. It's still not working, so I'm investigating my toolchain for problems. And I thiught this would be simple :(– jocalaOct 11, 2011 at 0:34
-
I tried to compile lighttpd for you (version 1.4.28) and discovered that you have set CFLAGS before configure. So CFLAGS='--static' ./configure. It gives ELF 32-bit LSB executable, ..., statically linked, not stripped. Sorry about the confusion with LDFLAGS and CFLAGS, it really depends on the package you are trying to compile ;-)– MichelOct 11, 2011 at 6:48