cURL / Mailing Lists / curl-library / Single Mail


Failure to compile curl 7.23.1 with static ssl on Darwin

From: Robert Banfield <>
Date: Fri, 09 Dec 2011 11:40:01 -0500

Problem: Compiling 7.23.1 on Darwin with a static version of SSL (and
passed to libcurl's configure script), successfully compiles libcurl but
fails in the linking stage to create the curl executable. This happens
only if there is a dynamic version of openssl somewhere in the system
library whose version differs from that passed to curl. Here is the
command that fails:

gcc [some cflags] -o curl [the object files] -L/path/to/openssl/lib
../lib/.libs/libcurl.a -ldl -lssl -lcrypto -lz

Undefined symbols:
   "_ERR_remove_thread_state", referenced from:
       _Curl_ossl_cleanup in libcurl.a(ssluse.o)

Openssl(system): 0.9.8
Openssl(passed to libcurl): 1.0.0

Reason: The directory search order is specified properly on down the
gcc->collect2->ld chain, however the way in which ld goes about its
search is to first search for dynamic libraries in each of the -L and
system directories, and then to search for static libraries in each of
the -L and system directories. By conducting the search in this way, a
dynamic openssl will /always/ override any static target specified with
the -l flag. To wit, passing the -search_paths_first option to
collect2/ld, or passing -Wl,-search_paths_first to gcc, successfully

 From man ld for -search_paths_first: "This option changes [the search
order] so that in each path `libx.dylib' is searched for then `libx.a'
before the next path in the library search path is searched."

I think the preferred method though is to not specify -l flags, but
instead to pass a static lib to gcc in the same form
../lib/.libs/libcurl.a is passed above, by just adding /path/to/libssl.a
and /path/to/libcrypto.a to the gcc command.
List admin:
Received on 2011-12-09