Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if one shared library depends on another shared library or not?

I wrote a shared library named "libmyssl.so", I use some openssl function in my code, the make file looks like follows:

g++ -v -shared -lz -lssl -lcrypto -Wl,-soname,libmyssl.so.1,-o libmyssl.so.1.0 myssl.o

After that, I use ldd command to look if it depends on libssl.so:

ldd libmyssl.so.1.0

The result as follows:

linux-vdso.so.1 =>  (0x00007fff743fe000) 
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0bc963b000) 
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0bc9276000) 
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0bc8f6f000) 
/lib64/ld-linux-x86-64.so.2 (0x00007f0bc9ea0000) 
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0bc8d59000)

It seems it didn't depend on libssl.so, am I right?

However, I use readelf -s command to see the symbols as follows:

readelf -s libmyssl.so.1.0

The reasult as follow:

......
259: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND SSL_new
260: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND SSL_get_shutdown
261: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND close@GLIBC_2.2.5 (4)
262: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND d2i_X509
263: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND X509_get_pubkey
264: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND SSL_set_info_callback
265: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND gmtime_r@GLIBC_2.2.5 (4)
......

It seems that the X509_get_putkey is not relocated. So it should depend on libssl.so. Maybe I didn't understand it well.

Hope someone can explain more about that, thanks very much!

like image 546
joe Avatar asked Nov 22 '16 10:11

joe


People also ask

What is a shared library in Linux?

A program would typically depend on other libraries to function. These libraries could either be compiled into the program itself or loaded from a shared library pool. The use of shared libraries reduces the program size and eases the development and distribution of the program. In Linux, shared libraries are stored in /lib* or /usr/lib* .

How to troubleshoot shared libraries not available in the system?

You will get the following error when the required library is not available in the system. You can check the shared libraries that a program depends on using ldd or other command-line tools to troubleshoot shared libraries loading issues. Launch your preferred terminal application. Get absolute path of the program you want to check.

Why can’t I run a program on another Linux distribution?

Different Linux distributions or even versions of the same distribution might package different libraries, making a program compiled for a particular distribution or version not correctly run on another. You will get the following error when the required library is not available in the system.


1 Answers

Some distributions would require you to list linked libraries after object files that reference them (to mimic how static libs work). So try to build like:

g++ -v -shared -Wl,-soname,libmyssl.so.1,-o libmyssl.so.1.0 myssl.o -lz -lssl -lcrypto
like image 59
yugr Avatar answered Oct 16 '22 15:10

yugr