[CMake] find_package with static library that uses pkg-config not working

Bill Somerville bill at classdesign.com
Sun Mar 30 06:45:32 EDT 2014


Hi,

I am using find_package to configure a library that uses pkg-config. 
When I configure and build a static only version of the library the link 
commands generated for my project are wrong.

The problem boils down to the fact that for static link of a library 
pkg-config needs to be called with the '--static' option to extract the 
correct compile switches and link libraries.

In my case the library libdl needs to be linked because the external 
library uses run time library loading. For example:

$ pkg-config --cflags --libs hamlib
-pthread -I/home/bill/test-install/hamlib/include 
-L/home/bill/test-install/hamlib/lib -lhamlib

$ pkg-config --cflags --libs --static hamlib
-pthread -I/home/bill/test-install/hamlib/include 
-L/home/bill/test-install/hamlib/lib -lhamlib -lm -ldl -lusb

So how do I get find_package to use the correct pkg-config invocation 
when there is no shared library version of the external library or if I 
want to force static linking of this external library?

TIA
Bill Somerville.


More information about the CMake mailing list