I have Ubuntu 14.04 upgraded from 12.04 making dist-upgrades. I did many manual installations such as ffmpeg, libglib and so on, in the past. I have a nice custom distro now, it works well but I have problems while trying to compile applications. It stems from library conflicts between manually installed packages from source code and native distro libraries. A guy advised me to rename /usr/local it works but boot failed on next reboot.

When I look for directories added by pkg-config with

  pkg-config --variable pc_path pkg-config

it lists


I don't want it to look for paths in /usr/local/lib...

How can I ban those paths not to let pkg-config look for?


Stuff in /usr/local usually supersedes stuff in /usr, so I'm a bit confused as to why you would install libraries there to have a "a nice custom distro", but then not want to compile against them. Those are the libraries the system will use actually use.

Anyway, man pkg-config claims the base search path:

is libdir/pkgconfig:datadir/pkgconfig where libdir is the libdir for pkg-config and datadir is the datadir for pkg-config when it was installed.

This implies they are compiled in. I notice it is different on ubuntu than fedora -- the former is long and inclusive, whereas the latter is short and exclusive; on fedora I have to set a $PKG_CONFIG_PATH to include /usr/local.

Since paths in $PKG_CONFIG_PATH are checked first, you could just set:


The fact that these are at the end of the built-in paths won't matter; if the check makes it to there without finding anything, there's nothing to be found.

To demonstrate how this works, create a temporary directory /opt/bs/pkg and copy a .pc file from one of the directories in the default path into it -- e.g., alsa.pc. First check;

> pkg-config --libs alsa

Now go into /opt/bs/pkg/alsa.pc and change -lasound (it's in the Libs: field) to -foobar. Set $PKG_CONFIG_PATH and try again:

> PKG_CONFIG_PATH=/opt/bs/pkg pkg-config --libs alsa

Eureka, $PKG_CONFIG_PATH has overridden the built-in paths...you can delete /opt/bs/pkg, of course.

  • I actually tried PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig beforehand but it didn't work. after setting PKG_CONFIG_PATH still pkg-config --variable pc_path pkg-config prints usr/local – kenn Jul 17 '14 at 13:50
  • 1
    Right -- you haven't changed the default path, but paths in $PKG_CONFIG_PATH are checked first. After you set it, you can check by calling, e.g. pkg-config --libs somepackage where "somepackage" has a .pc file in multiple places. – goldilocks Jul 17 '14 at 14:04
  • manpage says pkg-config retrieves information about packages from special metadata files. These files are named after the package, and has a .pc extension. On most systems, pkg-config looks in /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig and /usr/local/share/pkgconfig for these files. It will additionally look in the colon-separated (on Windows, semicolon-separated) list of directories speci‐ fied by the PKG_CONFIG_PATH environment variable. so isn't there any way to exclude /usr/local/share/pkgconfig ? – kenn Jul 17 '14 at 14:12
  • No, but it doesn't matter if you prioritize the paths you want to prioritize. I've added an example of what I'm talking about to demonstrate that using $PKG_CONFIG_PATH works. – goldilocks Jul 17 '14 at 14:29
  • let me test your method again, I got library error while compiling this github.com/MaartenBaert/ssr.git I hope it works, I believe I tried your method and it didn't work – kenn Jul 17 '14 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.