On 2017-03-13 23:04 +0000, lejeczek via gcc-help wrote: > if I linked a static lib and compilation rendered a dynamic lib, > now when I further compile and use that dyn lib, do I need > to include that static lib(s) I linked to the first time? It depends on whether you linked the symbols in the static lib into the dyn lib. If you built the dyn lib with cc -shared -fPIC libdyn_1.o libdyn_2.o -o a/libdyn.so -lstatic then the required symbols in libstatic.a would be added into libdyn.so. Then you can use -ldyn without -lstatic: cc main.c -La -ldyn However, if libdyn.so was built cc -shared -fPIC libdyn_1.o libdyn_2.o -o b/libdyn.so (without -lstatic) then the required symbols in libstatic.a would be undefined in libdyn.so. You would have to use -ldyn -lstatic: cc main.c -Lb -ldyn -lstatic If you objdump -t b/libdyn.so, you'll find symbols in libstatic.a which are "UND". And if you forgot -lstatic, the linker would complain like "undefined reference to <symbol name>". > I probably also make the question vague, if I could give you > a bit insight into a scenario... that could be one of those > (common?) where someone uses those specialised/optimized > math libraries. Then I think your dyn lib is like b/libdyn.so. For math libs, some developers intend to use static library since "-fPIC" would slow down the target code (a little). So the code in your static library is likely no PIC. They can't be linked into shared objects like we did for a/libdyn.so. So it's likely you have to use -ldyn -lstatic. On the other hand, if your static library is PIC, it's likely the shared version of this library is also existing. In this situation I suggest to use the shared version since shared librarys have many advantages (unless you want to ship only one shared object file without more dependencies). Best wishes. -- Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University