user391318 user391318 - 1 month ago 11
Linux Question

Undefined Reference Shared Object Linux [c++]

I have created a shared object named as a.so and it worked perfectly with an executable developed in c/c++ (linux). This shared object provides some functions for integration in external software. Below are some characteristics of this shared object:


  • Communicates with devices on RS232

  • TCP/IP + SSL communication with a server



Now I am creating JNI wrapper (b.so) of above shared object and used this command to open shared object and create a handler:

dlopen(FILE_NAME,RTLD_LAZY | RTLD_GLOBAL):

But it gives me error Unable to Load LIB : /usr/lib/a.so - [/usr/lib/a.so: undefined symbol: EVP_cleanup]

EVP_cleanup is used in a.so and is part of openssl/evp.h header file.

I tried to link ssl and crypto libs in b.so as well but output is same as above.

Can someone give me suggestions or an alternate method?

Thanks

Regards

Answer

It appears that you have linked your code only with libssl.so.

You must also explicitly link with libcrypto.so. EVP_cleanup() is defined in libcrypto.so.

objdump is a useful tool for figuring out what you need to link with, when documentation is lacking.

$ objdump -T /usr/lib64/libcrypto.so | grep EVP_cleanup
000000000012f5e0 g    DF .text  0000000000000054  libcrypto.so.10 EVP_cleanup