Skip to content
This repository has been archived by the owner on Nov 27, 2017. It is now read-only.

LinuxBrew overrides PKG_CONFIG_LIBDIR #47

Closed
agordon opened this issue Jan 8, 2014 · 8 comments
Closed

LinuxBrew overrides PKG_CONFIG_LIBDIR #47

agordon opened this issue Jan 8, 2014 · 8 comments
Assignees
Labels

Comments

@agordon
Copy link
Contributor

agordon commented Jan 8, 2014

Hello,

I encountered a strange conflict, regarding using a system-wide installed library through LinuxBrew+pkg-config - it seems LinuxBrew overrides PKG_CONFIG_LIBDIR, and so the native pkg-config can't find system-wide directories.

My setup:
Debian 7, /usr/bin/pkg-config works fine,
Some packages have "PC" files in /usr/lib/x86_64-linux-gnu/pkgconfig/ while others are in /usr/lib/pkgconfig - perhaps this is a new Debian thing?

Example 1:

$ dpkg -L libfftw3-dev | grep pc
/usr/lib/x86_64-linux-gnu/pkgconfig/fftw3f.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/fftw3.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/fftw3l.pc
$ pkg-config --libs --print-errors fftw3
-lfftw3 -lm

Example 2:

$ ls /usr/lib/pkgconfig/
cppunit.pc  python-2.7.pc

pkg-config by default searches both directories (without using ENV variables):

$ echo $PKG_CONFIG_PATH

$ echo $PKG_CONFIG_LIBDIR

$ pkg-config --list-all
fftw3f           FFTW - fast Fourier transform library
openssl          OpenSSL - Secure Sockets Layer and cryptography libraries and tools
fftw3l           FFTW - fast Fourier transform library
libcrypto        OpenSSL-libcrypto - OpenSSL cryptography library
zlib             zlib - zlib compression library
fftw3            FFTW - fast Fourier transform library
cppunit          CppUnit - The C++ Unit Test Library
python-2.7       Python - Python library
udev             udev - udev
expat            expat - expat XML parser
iso-codes        iso-codes - ISO country, language, script and currency codes and translations
libssl           OpenSSL - Secure Sockets Layer and cryptography libraries
shared-mime-info shared-mime-info - Freedesktop common MIME database

When I build a package (with ./configure) outside LinuxBrew, it works just fine.

Inside LinuxBrew, it fails by not finding fftw3 .

I can reproduce with the following formula:

require 'formula'

class Example < Formula
  homepage 'http://www.google.com'
  head 'https://github.com/Homebrew/homebrew-binary.git'

  def install
      system 'env | grep PKG'
      system 'pkg-config --print-errors --list-all'
  end
end

When running it, the output is:

$ brew install --HEAD --verbose $PWD/example.rb 
==> Cloning https://github.com/Homebrew/homebrew-binary.git
git clone --depth 1 https://github.com/Homebrew/homebrew-binary.git /home/admin/.cache/Homebrew/example--git
Cloning into '/home/admin/.cache/Homebrew/example--git'...
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 13 (delta 0), reused 10 (delta 0)
Unpacking objects: 100% (13/13), done.
git reset --hard origin/HEAD
HEAD is now at fd7f0c7 packer 0.4.1
git checkout-index -a -f --prefix=/tmp/example-l72M/
==> env | grep PKG
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig
==> pkg-config --print-errors --list-all
python-2.7 Python - Python library
cppunit    CppUnit - The C++ Unit Test Library
==> Cleaning
==> Finishing up
ln -s ../../Cellar/example/HEAD example
ln -s ../Cellar/example/HEAD example
==> Summary
/home/admin/source/LinuxBrew/Cellar/example/HEAD: 2 files, 12K, built in 2 seconds

Which shows that LinuxBrew added PKG_CONFIG_LIBDIR, and this messes up the default locations for debian (the --list-all doesn't show all the system packages).

What would be a recommended way to solve this?

Thanks,
-Gordon

@ghost ghost assigned sjackman Jan 8, 2014
@sjackman
Copy link
Member

sjackman commented Jan 8, 2014

Hi, Gordon. @villimagg is also experiencing this issue in #46. I leave for a conference on Friday and won't be able to look into this issue until February. Here's where Homebrew sets the PKG_CONFIG_LIBDIR environment variable. If you come up with a fix, please submit a pull request, and I'll incorporate it once I've returned.

https://github.com/Homebrew/linuxbrew/blob/linuxbrew/Library/Homebrew/extend/ENV/std.rb#L39
https://github.com/Homebrew/linuxbrew/blob/linuxbrew/Library/Homebrew/extend/ENV/std.rb#L96

Cheers,
Shaun

@agordon
Copy link
Contributor Author

agordon commented Jan 8, 2014

There's some interplay between PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH, which I'm not yet familiar with - so I don't have a ready solution.
To comments in the code explicitly mention "overriding the built-in paths" on purpose.
Perhaps adding several hard-coded paths for common linuxes? That will be ugly - but I don't know of a way to query "pkg-config" about the PATHs it will look it.

As a temporary work around, setting "PKG_CONFIG_PATH" before running "brew install" does solve it:

$ export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH
$ brew install XXXX

@villimagg
Copy link

Thank you. Will do that. Hope it goes well with finding a permanent
solution. I'll try to help as I can although I'm not a *nix expert.

On Wed, Jan 8, 2014 at 2:02 AM, A. Gordon notifications@github.com wrote:

There's some interplay between PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH,
which I'm not yet familiar with - so I don't have a ready solution.
To comments in the code explicitly mention "overriding the built-in paths"
on purpose.
Perhaps adding several hard-coded paths for common linuxes? That will be
ugly - but I don't know of a way to query "pkg-config" about the PATHs it
will look it.

As a temporary work around, setting "PKG_CONFIG_PATH" before running "brew
install" does solve it:

$ export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH$ brew install XXXX


Reply to this email directly or view it on GitHubhttps://github.com//issues/47#issuecomment-31799686
.

kv.
m.v.h.
regards,

Vilhjálmur Magnússon

@villimagg
Copy link

Alright, I'm running Fedora 20 64 bit and I've got two directories containing .pc files. Running whereis pkconfig in terminal gives me: pkgconfig: /usr/lib64/pkgconfig /usr/share/pkgconfig. The file bash-completion.pc lives inside my /usr/share/pkgconfig folder.

Wouldn't it be wise for me to add the PKG_CONFIG_PATH variable to my .bashrc file and concatenate the two paths into the PATH? e.g. PKG_CONFIG_PATH= /usr/lib64/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH

@agordon
Copy link
Contributor Author

agordon commented Jan 8, 2014

@villimagg - yes, you can add those directories to PKG_CONFIG_PATH in "~/.bashrc", and it should "just work".

@sjackman - Perhaps it's worth considering not overriding "PKG_CONFIG_LIBDIR" at all for LinuxBrew? Because on a "standard" linux, the system's native pkg-config installed and knows about all the different location? (as opposed to MacOS/HomeBrew, where the assumption is that pkg-config is not native) ?

And then, instead of overriding "PKG_CONFIG_LIBDIR", just append LinuxBrew's specific paths to PKG_CONFIG_PATH ?

I can send a patch for that, if this method is acceptable.

@villimagg
Copy link

That fixed it for me. Since people are running different linux distros one can run which pkconfig at terminal prompt and use the paths given to add to the PKG_CONFIG_PATH in their .bashrc.

In my case since I'm running Fedora 20 64 bit, when I run which pkgconfig in terminal I'm given:

$ which pkgconfig
pkgconfig: /usr/lib64/pkgconfig /usr/share/pkgconfig

I then run

$ echo "export PKG_CONFIG_PATH=\"/usr/lib64/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH\"" >> .bashrc

BUT
After I've logged back in again and open a terminal and run $ which pkgconfig again I get this:

$ which pkgconfig
/usr/bin/which: no pkgconfig in (/home/vmag/.rbenv/shims:/home/vmag/.linuxbrew/bin:/home/vmag/.rbenv/shims:/home/vmag/.linuxbrew/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/vmag/.local/bin:/home/vmag/bin)

/usr/bin/which: no pkgconfig in... Now what is that?

@sjackman
Copy link
Member

sjackman commented Jan 8, 2014

@agordon The Homebrew policy has always been to override any and every relevant environment variable. I can't say that I agree with that fully, but I don't want to override that policy on a piecemeal basis. For this reason, we created the --env=inherit option in Linuxbrew. This option indicates that system environment variables should be inherited and extended rather than overridden. So, please do use that option for your fix to pkgconfig. I'll review it and merge it when I'm back at the end of the month.

@sjackman sjackman removed their assignment Mar 20, 2014
@sjackman
Copy link
Member

Set PKG_CONFIG_PATH and/or PKG_CONFIG_LIBDIR and use --env=inherit.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants