Errors that relate to a bunch of unresolved OpenSSL characters that explicitly exist?

I am creating a shared library (we will call it "foo") that uses another library (we will call it "bar"). "bar" uses some functions from OpenSSL.

This is where the problem arises.

"bar" was compiled as a static library, and it turned out that OpenSSL too. So when I link the library ("foo"), I include:

  • object files for "foo"
  • static library libbar.a
  • OpenSSL static libraries libcrypto.a and libssl.a

The build command looks something like this:

 g++ -Wl,-soname,libfoo.so -shared file1.o file2.o libbar.a \ libcrypto.a libssl.a -o libfoo.so 

However, I get a lot of errors:

 ld: ./obj/libbar.a(file1.co): in function initialize_openssl: ssl.c:117: error: undefined reference to 'SSL_library_init' 

Running the following command:

 nm libssl.a | grep SSL_library_init 

It produces the following output:

 00000000 T SSL_library_init 

Thus, it is obvious that there is nothing wrong with OpenSSL libraries. What could cause something like that? Here are three commands used to build OpenSSL:

 export cross=arm-linux-androideabi- ./Configure android --prefix=~/openssl-arm make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib" 

The compilation process is complete without any errors, so I am completely puzzled.

Why am I getting linker errors that reference a bunch of OpenSSL characters that explicitly exist?

+6
source share
1 answer

The problem is caused by the order of the libraries in the link command. Switching the order of libcrypto.a and libssl.a allowed all characters.

GCC uses LD by default, and its one-pass linker. When you have two libraries, such as libssl and libcrypto , linked in a specific order, this means that libssl depends on the characters of libcrypto . Therefore, libssl must precede libcrypto (or libcrypto must follow libssl ). Unsurprisingly, libssl relies on libcrypto because libcrypto provides the cryptography used by libssl .

+3
source

All Articles