views:

147

answers:

6

Hello, In Linux, downloaded a program source and want it to be statically linked. Have a huge Makefile there, I

./configure
make

to compile. prehpes it's a bit too general to ask, but how can I make the binary statically linked? Thanks.

EDIT: the reason for this is wanting to make sure the binary will have no dependencies (or at least as few as possible), making it possible to run on any Linux based computer, even one without Internet connection, and non-updated Linux.

+1  A: 

Static linking is considered harmful! http://people.redhat.com/drepper/no_static_linking.html

I'm sorry, this is not a direct answer to your question, but I just wanted to point it out.

Suvesh Pratapa
Thanks for the link, I still want static linking, but will keep those warnings in mind.
Liran Orevi
+3  A: 

Yeah, you need to edit the make file and add the -static parameter to gcc during the link.

Byron Whitlock
+1  A: 

I assume it's using gcc to compile a series of c programs, although you will have to look in the Makefile to find out.

If so, you can adjust the gcc lines in the makefile to do static linking, although depending upon the structure of the program, this may be a complex change. Take a look at man gcc to see how this is done.

I'd be interested to know why you are statically linking. Have you considered using prelinking instead?

You should be aware that there may be licence problems to doing this if all components are not GPL.

Alex Brown
+6  A: 

Most autoconf generated configure script will allow you to make a static build:

 ./configure --with-static
 make

If that doesn't work, you may be able to pass linker flags in via LDFLAGS, like this:

 ./configure LDFLAGS=-static
eduffy
Very good answer, unfortunately both didn't work for some reason.
Liran Orevi
From what I understand it didn't work because I was lacking the static libraries to link with.
Liran Orevi
+1  A: 

If you cannot compile a static binary, I've had good results using Statifier.

Bash
Excellent idea.I had very good results with a similar product.
Liran Orevi