Possibly wrong library linked when program has both static and dynamic dependencies
Hello! We've come across a particular (maybe?) use case when the wrong library (installed instead of in-project one) could be used for a program that depends (links) both static and dynamic libraries at the same time.
In general for libraries waf will respect the "use order" when specifying parameters to the compiler/linker. The fact is that since all the static library flags (namely -L
for directories and -l
for libraries) are grouped and always preceding the ones for dynamic ones, then if a dynamic library is found (by chance) in one of the directories of the static ones (since seemingly -L
and -l
options are "global" and not bound just to the particular "-Wl,-Bxxx" directive, see for example here under -L
options).
This can lead specifically to the fact that when building such a project, the library from the static library directory has even precedence on the internal project one.
So to recap:
- A static library is in some specific
$PREFIX
directory - A project consisting in a dynamic library and a program (which depends both on the internal dynamic library and external static one) is built and installed in that same directory
$PREFIX
- Next time the project is built, the linking of the program will now happen with the dynamic library from
$PREFIX
that was previously installed and not as expected with the one inside the project
This can in principle happen also with the default /usr/local
directory, as far as it is explicitly (and not as one of the default linker paths) included in the paths when linking to the library (in general pkg-config files or such may strip default paths).
As I realize the description may be hard to understand, I've created (attached) a minimal reproducer with the steps to reproduce that could hopefully help. In the tar there is a README.txt
that should hopefully explain in detail how to reproduce step by step.
The use case doesn't sound too "out of the world" as it may be reasonable that while developing one is also installing (ie. for system/integration tests) to a common directory. Specifically indeed this happened to us when having multiple dependent waf project (with some of the early ones creating and installing static libraries) that used the common directory for integration.
Ideas came out to solve this:
- Don't have two separate lists (STLIBPATH/LIBPATH) but manage one (so order can be preserved also if types of libraries are different)
- Split each of the two lists in a in-project one and a external one and then first put both in-project ones and then both external, so we know that all project search paths will always come first
Many thanks for any input! F.