Basic question: Can one specify, when building a static library (and ONLY when building the static library), that the static library needs to link with a shared object?
I'm working on a project that looks like this:
I only own StaticLib.
I'd like to add a dependency on a 3rd party SharedObject to the StaticLib. I know that the 3rd party SO exists on all the machines that my software is going to run on, which is good because I'm also restricted by licensing from distributing that 3rd party SO in anyway.
Just playing around, I can get it to work so long as I tell the linker at every application level that I need to link with the 3rd party SO. The problem is twofold: I don't own the build process for those applications AND I'm actually simplifying and there are a lot of applications and SOs that use my static library, some of which are completely outside of my org and I don't know what they are.
As I said, I'm restricted by licensing from distributing the 3rd party SO, so the solutions I've seen that talk about how to fold the SO into a static library won't work for me; that would be distributing the 3rd party SO and I'm legally blocked from doing that.
Is there any way to make this work?
As a follow up, MOST of the uses of my static library will be via SharedObject. If there's a way to make this work such that I must modify the build process for the handful of applications that directly use StaticLibrary and and modify the build of SharedObject, but not have to modify the build of applications that use SharedObject, that'd be workable.
A static library as input to the GNU linker is a simple archive of object files from which the linker will copy and statically link into the output image exactly those object files, if any, that provide the linkage with definitions for symbols that are already referred to in the linkage but so far lack definitions.
A static library contributes nothing whatsoever to the linkage but the 0 or more object files that are extracted from it.
So your question boils down to: Is there a way in which gcc
can compile an object file that
when input to a linkage will instruct the linker to find a specified
shared libary and input it to the linkage?
There isn't.
High-level build system generators (autotools, cmake, meson, buck, etc.) will enable you to specify somehow that when a library A is in the linkage of a build target then so will be libraries B, C ..., in that order. The details vary. You might distribute such a build system.