Search code examples
gccpkg-config

How does PKG-CONFIG select between two .pc files?


I have two .pc files for glib-2.0

/usr/lib/x86_64-linux-gnu/pkgconfig/glib-2.0.pc
/usr/local/lib/pkgconfig/glib-2.0.pc

They differ with where they point the location of include files.

/usr/lib/x86... points to /usr/include
/usr/local/lib... points to /usr/local/include

This causes a problem when I run:

pkg-config --cflags gtk+-3.0

this returns the following glib-2.0 search locations:

-I/usr/local/include/glib-2.0 
-I/usr/local/lib/glib-2.0/include 

whereas my package manager has installed the glib libraries to

/usr/include/glib 

Question 1: Why is the PKG-CONFIG selecting the second location compared to the first? How can I change this?

Question 2: Is it abnormal to have two of the same .pc files?

Question 3: If I do want to delete one of the .pc files, can I do so safely?

Note:

  1. I do not wish to copy over the glib library to /local/ as the package manager will loose sight of this.
  2. I do not wish to add -I/usr/include in addition when running gcc as I expect PKG-CONFIG to work properly. (I also think this will cause other problems which I will have to manually modify)

Solution

  • You can use PKG_CONFIG_LIBDIR environment variable to override the default search directory.

    There's also PKG_CONFIG_PATH that can be used as a colon-separated list of directories to search for .pc files.

    See pkg-config's manual page for more info.