Question

I maintain our in-house infrastructure library - lets call it libcluracan. This library has to be statically linked because it doesn't exist on outside computers where the code is used.

This means that instead of creating a libcluracan.so file using the linker I create a libcluracan.a file using the ar command

Now I'm trying to add some new functionality to libcluracan, but it requires linking with an outside library - specifically -lfltk, but the specifics aren't important. What is important is that I can assume the outside computers have this library (and any other publicly available library I need).

The biggest problem is that I can't change how the in-house programmers compile (well, link) their code.

Had we been using a dynamic libcluracan.so library I'd just add -lfltk to the linker and forget about it - the programmers would continue to link with -lcluracan and get -lfltk automatically.

I need to find a way to do the same thing with our static libcluracan.a library.

TL;DR

Is there a way to create a static .a library that automatically links to another dynamic .so library when used?

Was it helpful?

Solution

The biggest problem is that I can't change how the in-house programmers compile (well, link) their code.

That is indeed a big problem. Your in-house programmers should be using make (or a similar automated build system), and the change would be trivial.

There is no way to achieve what you want on an arbitrary UNIX system.

IF you are using GNU toolchain, and in particular GNU-ld or gold, THEN you can achieve what you want by linking with libcluracan.so, where libcluracan.so is not a shared library, but a linker script, which looks like this:

GROUP ( libcluracan.a libfltk.so )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top