Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to statically-link a complex program

Tags:

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?

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.

like image 795
Liran Orevi Avatar asked Jun 11 '09 20:06

Liran Orevi


2 Answers

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

 ./configure --enable-static  make 

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

 ./configure LDFLAGS=-static 
like image 154
eduffy Avatar answered Sep 19 '22 14:09

eduffy


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

like image 41
Byron Whitlock Avatar answered Sep 18 '22 14:09

Byron Whitlock