Let’s say I’m working on a static library foo.a, which makes use of a function in bar.so.
How do I build this library in such a way that anyone who uses foo.a in their project doesn’t have to explicitly link against bar.so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you can do in
libfoo.ais make a call todlopento dynamically linklibbar.so. Then, usedlsymto locate the function you want to use.libbar.soshould be a C library, or the function should beextern "C"if a C++ library, for you to find the function name properly. Otherwise you will need to mangle the name to find the function withdlsym. You can useobjdump -Ton the library to check if the names in the library are mangled.Realize there is still a dependency on
libbar.so, but it is baked into your static library. So the user oflibfoo.adoes not have to add-lbarto the link line when they link in-lfoo.