How can I exclude some library paths listed in " pkg-config --variable pc_path pkg-config"?
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:
PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
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
-lasound
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
-foobar
Eureka, $PKG_CONFIG_PATH
has overridden the built-in paths...you can delete /opt/bs/pkg
, of course.
kenn
Updated on September 18, 2022Comments
-
kenn over 1 year
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
withpkg-config --variable pc_path pkg-config
it lists
/usr/local/lib/i386-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
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? -
goldilocks almost 10 yearsRight -- 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. -
kenn almost 10 yearsmanpage 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
? -
goldilocks almost 10 yearsNo, 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.
-
kenn almost 10 yearslet 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
-
goldilocks almost 10 yearsIt works to do what you've asked for in the question, so if you use it properly and have errors compiling something, the problem isn't to do with what you've asked about.
-
kenn almost 10 yearsUnfortunately it doesn't work. It's permissive and allows looking for libraries in
usr/local/...
I think only way to achieve what I want is to rename pkgconfig directories inusr/local
as a workaround -
goldilocks almost 10 yearsOkay, but the only way it will find those is if the libraries are not installed anywhere else. In this case your choices are: 1) Use version from
/usr/local
. 2) Do not use the library at all, in which case, if they are required,./configure
will bail out. If it's choosing a.pc
file from/usr/local
when there is one in/usr
then you did not export $PKG_CONFIG_PATH properly. End of story. There is no ambiguity about this.