29

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?

Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162

2 Answers2

38

Try this:

./configure LDFLAGS="-static"
ams
  • 24,923
  • 4
  • 54
  • 75
  • But I get a lot of `warning: Using 'xxx' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking` – gatopeich Sep 24 '14 at 15:31
  • Yes, that's true, there are some things that will be `dlopen`d at runtime. I think DNS lookups need this, for one. It's not ideal. :-( – ams Sep 24 '14 at 15:52
  • If you are trying to static link against glibc, you can't run on OmniOS anyway, which requires the illumos libc -- glibc only works with a Linux kernel. – alanc Apr 29 '15 at 05:54
  • 5
    I'm getting `configure: error: C++ compiler cannot create executables` when I run this flag. – Bryce Guinta Mar 11 '17 at 17:47
  • 3
    My error was caused by a missing package, `libstdc++-static` since the program under question was using c++. [This tutorial helped me](https://www.systutorials.com/5217/how-to-statically-link-c-and-c-programs-on-linux-with-gcc/) – Bryce Guinta Mar 11 '17 at 18:46
28

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

srd
  • 1,207
  • 12
  • 13
  • 5
    It's important here that, as shown, `LDFLAGS="-all-static"` is given _only_ to `make`, and not set at `./configure` time, because otherwise it would break the configure scripts (because only the `libtool` wrapper accepts it, compilers like `gcc` themselves do not). – nh2 Aug 11 '19 at 02:35
  • 1
    Yet another reason to hate autotools. :( – user1202136 Nov 21 '20 at 19:09
  • 1
    Just a heads up, be sure to note the generated LDFLAGS from `configure`'s output. You may be required to re-add any other options that are present, like `-L` to include specific library paths. – Mr. Llama Jun 29 '22 at 18:46