two shared libraries liba.so and libb.so. liba.so uses libb.so. All c files are compiled with -fPIC. Linking uses -shared. When we call dlopen on liba.so it cannot find symbols in libb.so…we get the “undefined symbol” error. We can dlopen libb.so with no errors. We know that liba is finding libb because we don’t get a file not found error. We get a file not found error when we delete libb.so. We tried -lutil and no luck.
Any ideas????
oh yeah. gcc 4.1.2
update: We use rpath when linking liba so it can find libb.
ldd liba.so returns:
linux-gate.so.1 => (0xffffe000)
libb.so => ./libb.so (0xf6ef9000) <-------- LIBB
libutil.so.1 => /lib/libutil.so.1 (0xf6ef5000)
libdl.so.2 => /lib/libdl.so.2 (0xf6ef1000)
libm.so.6 => /lib/libm.so.6 (0xf6ec9000)
libpthread.so.0 => /lib/libpthread.so.0 (0xf6eb1000)
librt.so.1 => /lib/librt.so.1 (0xf6ea8000)
libc.so.6 => /lib/libc.so.6 (0xf6d62000)
/lib/ld-linux.so.2 (0x007d0000)
is it significat that there is no .# at the end of libb???
You can easily check where
libb.sois expected to be withlddcommand:If it’s
not found,libb.so‘s path should be added to/etc/ld.so.confor shell variableLD_LIBRARY_PATH.Another way is setting
rpathin theliba.soitself – it’s basically hardcoding its path so when the binary is started the dynamic linker would know where to search for the shared libraries.If
rpathis not set it will first search inLD_LIBRARY_PATH, then the paths mentioned in/etc/ld.so.conf(or /etc/ld.so.conf.d/). After adding tols.so.confdon’t forget to execute/sbin/ldconfigDynamic linker searches the dependent shared libraries by their
soname(if it’s set) – ifsonameis not set (with -Wl,-soname,libb.so.1 for example), it will be searched by library’s name.Example:
libb.so.1.0is your actual library, havingsoname–libb.so.1. You would normally have the following files structure:where
libb.soandlibb.so.1are symlinks.You usually link to
libb.so, when building some application or other library, depending onlibb.so.When the application is started (or dlopen is executed – your case) – the dynamic linker will search for file with name
libb.so.1– thesonameof dependent library, if thesonameis set, notlibb.so.That’s why you need that symlink
libb.so.1, pointing to the actual library.If you use
ld.so.confandldconfig, it will create the symlink withsoname‘s name, pointing to the library file, if this symlink is missing.You can see ld-linux man page for more useful info.
If the library is found but some of the symbols are missing, try building
libb.sowith-Wl,--no-undefinedoptionIt should give you an error if you missed to define some symbol.