preserving order of linker flags

Stefan Vigerske stefan at math.hu-berlin.de
Sat Jan 22 06:41:24 PST 2011


Hi,

in our buildsystem, there can be unfortunate situations where the 
"Libs:" line of a .pc file contains libraries that are referenced once 
by their absolute path and once via -L,-l syntax, e.g., -l1 /mine/lib2.a
Now, the first library may depend on the second one, which in a static 
build requires to have /mine/lib2.a after -l1 on the linker line.
However, pkg-config seem to reorder the flags by moving the second 
library to the front. :-(
Is there any way how to avoid this behaviour, i.e., to tell pkg-config 
to keep the relative order of the entries in the "Libs:" field?

To reproduce, consider a file a.pc with content:
Name: a
Version: 1.0
Description: a
Libs: -l1 /mine/lib2.a

Then "PKG_CONFIG_PATH=. pkg-config --libs a" gives
/mine/lib2.a -l1

Thank you,
Stefan

PS: Reformulating /mine/lib2.a as -L/mine -l2 is not possible since, 
first, these are linker flags provided by a user from "outside", and, 
second, because /mine/lib2.a is used since there is already a 
/usr/lib/lib2.a, which may be choosen instead of /mine/lib2.a, if the 
-L,-l syntax is used.


More information about the pkg-config mailing list