0

I recently added libcurl dependency to my c++ library. I statically compiled libcurl with-nss for https support. I use Debian 7 for compilation.

I create two builds for my library - static and shared

Shared version is linking fine with binaries built on any Linux distro, but the static build only links with binaries when compiled on Debian 7.

I tried static linking on Ubuntu 16.04, Debian Stretch but all are reporting following error during compilation:

g++ -Wall -o Sample Sample.cpp -Wl,-Bstatic -L. -lMyLibrary -Wl,-Bdynamic  -lssl3
/usr/bin/ld: ./libMyLibrary.a(libcurl_la-nss.o): undefined reference to symbol 'CERT_GetDefaultCertDB@@NSS_3.2'
//usr/lib/x86_64-linux-gnu/libnss3.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:22: recipe for target 'Sample' failed
make: *** [Sample] Error 1

Static compilation now only works on Debian 7 which is a big problem.

adnan kamili
  • 8,967
  • 7
  • 65
  • 125
  • Related: https://stackoverflow.com/q/12573816/2371524 -- with static libraries, there are no automatic dependencies, you must link anything the library needs yourself. So, find who defines this symbol and link it. –  Apr 30 '18 at 09:04
  • @FelixPalmen Thanks adding following libs fixed the issue -lssl3 -lnss3 -lnspr4 , please add this as an answer – adnan kamili Apr 30 '18 at 09:13

1 Answers1

1

Static libraries are just archives of object files. As one consequences, they don't carry any dependency information. So, if you link a static library which depends on some other libraries, you have to add these explicitly in your linking command.

In your case, this means:

  • find whoever defines CERT_GetDefaultCertDB@@NSS_3.2 -- some answers to this FAQ could help here
  • add this library to your linker command (with -l, after your static library)