I’ve got a shared library with some homemade functions, which I compile into my other programs, but I have to link the end program with all the libraries I have used to compile the static library. Here is an example:
I have function foo in the library which requires a function from another library libbar.so.
In my main program to use function foo I have to compile it with the -lbar flag. Is there a way I can compile my library statically so it includes all the required code from the other libraries, and I can compile my end program without needing the -lbar flag?
Shared objects (.so) aren’t libraries, they are objects. You can’t extract part of them and insert it in other libraries.
What you can do if build a shared object which references the other — but the other will be needed at run time. Just add the -lbar when linking libfoo.
If you are able to build libbar, you can obviously make a library which is the combination of libfoo and libbar. IIRC, you can also make the linker build a library which is libfoo and the needed part of libbar by linking a .a with the .o meant to go in libbar. Example: