Use the -l:lib syntax when pkg-config is called with --static

Open Nicolas Caramelli requested to merge caramelli/pkg-config:master into master

Libraries from Requires.private and Libs.private will only be included when static linking. So, for static linking, pkg-config is used with the --static option.

cc `pkg-config --static --cflags --libs name` -o myapp myapp.c

We expect that the static version of the libraries are used during the link of myapp (libname.a as well as the .a libraries from Requires.private and Libs.private). But if both versions of the libraries (static and dynamic) are available, the dynamic version (.so) is preferred by the linker.

This change proposes to replace the -l part for libraries using the -l:lib syntax when pkg-config is called with the --static option (-lname is replaced by -l:libname.a). So a static link is done as expected, even if a dynamic version of the libraries is available.

The current implementation of this change is certainly not perfect, but is deliberately as simple as possible to focus on the principle of the proposal.

Edited by Nicolas Caramelli

Merge request reports