openssllibcurlstatic-linkingnm

Building libcurl with static linking to openssl


I am trying to build libcurl with static linking to openssl. So to achieve that, I have used following configuration:

OpenSSL:

LDFLAGS="-static”
LIBS="-ldl”

cURL:

LDFLAGS="-static”
CPPFLAGS="-I$(CURDIR)/$(3RDPARTY_DIR)$(OPENSSL)/include   
LDFLAGS="-L$(CURDIR)/$(3RDPARTY_DIR)$(OPENSSL)"
./configure --disable-shared --without-zlib --without-libidn --without-librtmp --disable-ldap —-with-ssl=<path where my openssl is installed>

With this, I am to generate libcurl.a and link it to my code where I am successfully able to handle HTTPS connections, as per my need.

But for the sake of learning purpose, I wanted to know are SSL symbols actually integrated into libcurl or not. So for that, I tried using nm command:

nm -A libcurl.a | grep “SSL_"

But it shows all SSL symbols as Undefined. For example,

U SSL_connect
U SSL_ctrl

So does it mean that symbols from libssl.a and libcrypto.a are NOT actually integrated into libcurl?

If yes, what can be done to actually integrate them into libcurl.a?

Any help is appreciated to help me understand this.


Solution

  • Yes, it means that the OpenSSL symbols are not integrated into libcurl.

    When you build a static version of libcurl, you get a libcurl.a file suitable for static linking. But you then need to also provide all the (static) dependency libraries as well on the linker command line, you don't normally link them all together into a single static lib first. (If you want that done, you will have to do it yourself; the curl build system won't do it.)

    When you want to link your application with a static libcurl built to use a static OpenSSL, you link your application and provide all the necessary libs on the linker command line. On a *nix that means -lcurl -lcrypto -lssl...

    (Most libcurl builds will also use additional dependencies).