Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to static link Linux software that uses ./configure?

Tags:

I would like to compile NRPE static, so I can copy the compiled binary to an OmniOS server, where I don't want gcc to be installed on. I would prefer to install NRPE with SSl support from a repository, but such doesn't seam to exist, so I would like to compile it myself. However the ./configure script doesn't contain a static option it seams

~/nrpe-2.15# ./configure --help | grep static ~/nrpe-2.15# ./configure --help | grep share   --datadir=DIR          read-only architecture-independent data [PREFIX/share]   --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com] 

Question

How do I compile a program that uses configure statically?

like image 247
Sandra Schlichting Avatar asked Nov 19 '13 10:11

Sandra Schlichting


People also ask

How do I create a statically linked executable in Linux?

Create a statically linked application The -I option tells GCC to search for header files listed after it. In this case, you're specifying the current directory, represented by a single dot ( . ). Link mathDemo.o with libmymath. a to create the final executable.

How static linking works?

Static linking is the result of the linker copying all library routines used in the program into the executable image. This may require more disk space and memory than dynamic linking, but is both faster and more portable, since it does not require the presence of the library on the system where it is run.

When to use static linking?

The main difference between static and dynamic linking is that static linking copies all library modules used in the program into the final executable file at the final step of the compilation while, in dynamic linking, the linking occurs at run time when both executable files and libraries are placed in the memory.

What is GCC static?

The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run. To achieve static linking requires that the archive ( . a ) versions of your libraries exist on the system. so /usr/lib/libc.


2 Answers

Try this:

./configure LDFLAGS="-static" 
like image 195
ams Avatar answered Sep 28 '22 20:09

ams


For people coming from google, I found that if you have libtool part of your build, you will need to:

  1. ./configure CFLAGS="-static" ....
  2. make LDFLAGS="-all-static"

You can see that -all-static with libtool --help --mode=link

like image 41
srd Avatar answered Sep 28 '22 18:09

srd