I've built a project SharedProj that is linked to .so. It links 4 more projects, that are built to static libraries: libA.a, libB.a, libC.a, libD.a. These projects are set as references in SharedProj.so and linked with -l flag.
When I try to load SharedProj.so from Python with cdll.LoadLibrary, it fails with exception: "cannot find libA.so - no such file". Yes, it's really true: there's no libA.so and not supposed to be. There's libA.a, that is linked statically.
What is the problem here? How do I build SharedProj.so properly, so Python will load it correctly?
I've tried linking SharedProj.so with -shared or -shared-libgcc flags. Tried to build the static libraries with -static or -static-libgcc flags. Tried to add or remove -fPIC flag.
I've solved the problem in Eclipse IDE. Apparently, the problem was that my static libs libA.a, libB.a, libC.a have used another libs, like math lib, and I haven't specified the linker where it must search for them. In the final link directive I pass with -L flag the folders of my static libs AND the /lib folder. With -l flag I specify the names of the static libs: libA, libB, libC. Also the following flags are included: -shared -shared-gcclib -m64 Also, a directive to the linker to pull all the symbols into the .so must be included: -Wl,--whole-archive all_the_static_libs.a -Wl,--no-whole-archive. So, finally, the linkage line looks like this:
g++ -L"%workspace/libA/Debug" -L"%workspace/libB/Debug" -L"%workspace/libC/Debug" -L/lib -Wl,--whole-archive -llibA -llibB -llibC -Wl,--no-whole-archive -m64 -shared-libgcc -shared -o "SharedProj.so" ./SharedProj.o