c++ - Shared library compiled by me won't load and error message is virtually useless -


i'm write linux c++ app uses shared libraries plugins. (i'm going use term dll here because .so clumsy) shared library system seems weak on error detail. whenever there problem of kind, error is: no such file or directory, though in every case dll file there , strace shows app opens file.

pcap.so code , loads various other system dll files. open("./tls/x86_64/pcap.so", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./tls/pcap.so", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./x86_64/pcap.so", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./pcap.so", o_rdonly|o_cloexec)   = 3 read(3, "\177elf\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200c\1\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=s_ifreg|0775, st_size=752011, ...}) = 0 getcwd("/home/woody/projects/wiregrep", 128) = 30 mmap(null, 2264832, prot_read|prot_exec, map_private|map_denywrite, 3, 0) = 0x7fdb8cc88000 mprotect(0x7fdb8ccb0000, 2093056, prot_none) = 0 mmap(0x7fdb8ceaf000, 8192, prot_read|prot_write, map_private|map_fixed|map_denywrite, 3, 0x27000) = 0x7fdb8ceaf000 close(3)                                = 0 open("./tls/x86_64/libtins.so.1", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./tls/libtins.so.1", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./x86_64/libtins.so.1", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./libtins.so.1", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("/etc/ld.so.cache", o_rdonly|o_cloexec) = 3 fstat(3, {st_mode=s_ifreg|0644, st_size=95890, ...}) = 0 mmap(null, 95890, prot_read, map_private, 3, 0) = 0x7fdb8e128000 close(3)                                = 0 access("/etc/ld.so.nohwcap", f_ok)      = -1 enoent (no such file or directory) open("/usr/lib/x86_64-linux-gnu/libtins.so.1", o_rdonly|o_cloexec) = 3 read(3, "\177elf\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360~\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=s_ifreg|0644, st_size=465904, ...}) = 0 mmap(null, 2561000, prot_read|prot_exec, map_private|map_denywrite, 3, 0) = 0x7fdb8ca10000 mprotect(0x7fdb8ca7f000, 2093056, prot_none) = 0 mmap(0x7fdb8cc7e000, 16384, prot_read|prot_write, map_private|map_fixed|map_denywrite, 3, 0x6e000) = 0x7fdb8cc7e000 close(3)                                = 0 open("./tls/x86_64/libcrypto.so.1.0.0", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./tls/libcrypto.so.1.0.0", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./x86_64/libcrypto.so.1.0.0", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./libcrypto.so.1.0.0", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) access("/etc/ld.so.nohwcap", f_ok)      = -1 enoent (no such file or directory) open("/lib/x86_64-linux-gnu/libcrypto.so.1.0.0", o_rdonly|o_cloexec) = 3 read(3, "\177elf\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\356\5\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=s_ifreg|0644, st_size=1930528, ...}) = 0 mmap(null, 4040856, prot_read|prot_exec, map_private|map_denywrite, 3, 0) = 0x7fdb8c630000 mprotect(0x7fdb8c7e2000, 2093056, prot_none) = 0 mmap(0x7fdb8c9e1000, 155648, prot_read|prot_write, map_private|map_fixed|map_denywrite, 3, 0x1b1000) = 0x7fdb8c9e1000 mmap(0x7fdb8ca07000, 14488, prot_read|prot_write, map_private|map_fixed|map_anonymous, -1, 0) = 0x7fdb8ca07000 close(3)                                = 0 open("./tls/x86_64/libpcap.so.0.8", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./tls/libpcap.so.0.8", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./x86_64/libpcap.so.0.8", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) open("./libpcap.so.0.8", o_rdonly|o_cloexec) = -1 enoent (no such file or directory) access("/etc/ld.so.nohwcap", f_ok)      = -1 enoent (no such file or directory) open("/usr/lib/x86_64-linux-gnu/libpcap.so.0.8", o_rdonly|o_cloexec) = 3 read(3, "\177elf\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 l\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=s_ifreg|0644, st_size=249096, ...}) = 0 mmap(null, 2347480, prot_read|prot_exec, map_private|map_denywrite, 3, 0) = 0x7fdb8c3f0000 mprotect(0x7fdb8c42b000, 2093056, prot_none) = 0 mmap(0x7fdb8c62a000, 12288, prot_read|prot_write, map_private|map_fixed|map_denywrite, 3, 0x3a000) = 0x7fdb8c62a000 mmap(0x7fdb8c62d000, 472, prot_read|prot_write, map_private|map_fixed|map_anonymous, -1, 0) = 0x7fdb8c62d000 close(3)                                = 0 mprotect(0x7fdb8c62a000, 8192, prot_read) = 0 mprotect(0x7fdb8c9e1000, 110592, prot_read) = 0 mprotect(0x7fdb8cc7e000, 12288, prot_read) = 0 munmap(0x7fdb8e128000, 95890)           = 0 munmap(0x7fdb8cc88000, 2264832)         = 0 munmap(0x7fdb8ca10000, 2561000)         = 0 munmap(0x7fdb8c630000, 4040856)         = 0 munmap(0x7fdb8c3f0000, 2347480)         = 0 munmap(0x7fdb8ceb8000, 2661832)         = 0 write(1, "error:unable load shared libr"..., 100error:unable load shared library(2): pcap.so no such file or directory at:plugin.h_26 ) = 100 exit_group(-1)                          = ? 

this shows loading dependent dlls , work when compiled static library executable. why fails toward end opaque me. there's no indication of why it's being munpap'ed out of memory.

i've worked through several types of errors cause , different (unresolved externals, no --export-dynamic in main framework code loads plugins, etc). got the point first create simple app using dll code in static link, main statement able see error detail prior dll'izing code. pcap.so works fine executeable won't load dll.

i compile this:

virtualbox-3:~/projects/wiregrep$ make pcap.so g++-4.7 -std=c++11 -d__stdc_format_macros -wno-deprecated -g  -i. -fpic -wl,--export-dynamic  -wall    -c -o pcap.o pcap.cc g++-4.7 -wl,--export-dynamic -shared -o pcap.so pcap.o mylibs/libmm.a -ltins  

the code loads actual dll looks this:

   void load(const char* classname) {     if (classname)         (sharedlibraryfilename = classname) += ".so";      sharedlibraryhandle = ::dlopen(sharedlibraryfilename, rtld_lazy|rtld_global);      if (sharedlibraryhandle == null) // strerror implicitly in resultin g message         throw exception(location, "unable load shared library(%d): %s", errno, sharedlibraryfilename.c_str()); } 

i'm not concerned particular situation having better way debug opaque process linux uses load dll.

i have several other similar dlls load fine had debug-in-the-blind resolve problems in each of them them work.


Comments