#11 Static linkage (solved)


Hello Team,

I am trying to link esniper statically for a small environment.

First some info on my build environment:
uname -a
Linux linvdr 2.6.9 #1 Tue Nov 2 08:08:39 CET 2004 i686 unknown unknown GNU/Linux
gcc --version
gcc (GCC) 3.4.4
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

My curl version (sources) is curl-7.19.7, esniper version is esniper-2-21-0.

I did a build of curl with static linkage by running its 'configure' script with parameter '--disable-shared' followed by 'make' and 'make install'. As of this I got static libs of curl

ls -1 /usr/local/lib/

Running esnipers 'configure' gives an error now.

checking for curl_easy_setopt... no
configure: error: cURL 7.1.1 or newer required (cURL is available from http://curl.haxx.se/\)

from 'config.log' I can see that the test compilation run is missing 'curl_easy_setopt'

gcc -o conftest -I/usr/local/include -g -O2 -L/usr/local/lib -lcurl -lssl -lcrypto -lz conftest.c
/tmp/cc8zFxWa.o: In function `main':
/root/esniper-2-21-0/conftest.c:45: undefined reference to `curl_easy_setopt'
collect2: ld returned 1 exit status

So far so good. Now I tried to configure with static linkage. I did this by an invocation with CFLAGS as option

./configure CFLAGS='-static -L/usr/local/lib -lcurl -lssl -lcrypto -lz'

this give the same error as before, the log file 'config.log' now shows something strange

checking for curl_easy_setopt
gcc -o conftest -I/usr/local/include -static -L/usr/local/lib -lcurl -lssl -lcrypto -lz -L/usr/local/lib -lcurl -lssl -lcrypto -lz conftest.c >&5
/tmp/ccG9RBm5.o: In function `main':
conftest.c:(.text+0x1d): undefined reference to `curl_easy_setopt'

It looks to me that static linkage is not done (or curl lib is not found). What bothers me is the duplicate collection of the libraries in the gcc invocation.

I tried a small C program and was able to do a static linkage with that

#include <stdio.h>
extern char curl_easy_setopt ();
int main () {
printf("%p\n", curl_easy_setopt);
return curl_easy_setopt ();

gcc -o test test.c -static -lcurl -lssl -lcrypto -lz
file test
test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped

Find the 'config.log' attached, any help greatly appreciated and thanks in advance


  • Thorsten Reimers

    Config.log of invocation ./configure CFLAGS='-static -L/usr/local/lib -lcurl -lssl -lcrypto -lz'

  • Thorsten Reimers


    I have been able to solve my problem and want to share my findings.

    It took me a moment to understand, what was going wrong. There is a difference between static and shared linkage (apart from the obviously). When static linkage is done the libraries are searched in the order given. That is if a link run is made with libraries A, B and C where A request symbols in B and B request symbols in C the correct order must be observed. The link invocation should use the order

    -lA -lB -lC

    if this is not adhered symbols will be missing.

    For an object file the same is true. If an object file test.o is using A, B and C (as above) the correct link invocation is

    gcc -static -o test test.o -lA -lB -lC


    gcc -static -o test -lA -lB -lC test.o

    will again claim missing symbols. This is because the linker adds symbols from libraries on demand. It will adhere to the order of the object and library files and will add symbols of A, B or C only, if they are required (when the libraries are encountered).

    For esniper my solution was to correct the configure script. I adjusted the order in all linker invocations by swapping the program file and the LDFLAGS, for example from

    ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'


    ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS conftest.$ac_ext $LDFLAGS $LIBS >&5'

    With this correction the invocation of

    ./configure -static

    worked out of the box. The make run created a statically linked program. Find attached the adjusted configure script.

  • Thorsten Reimers

    • summary: Static linkage --> Static linkage (solved)
  • Thorsten Reimers

    Adjusted configure script for static linkage

  • Scott Nicol

    Scott Nicol - 2009-11-12

    Thank you! configure is generated, so we'll have to figure out how to put this into configure.in.

  • Thorsten Reimers

    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks