7

I have a bunch of libraries installed with homebrew but I don't know what the right way to get them in pkg-config's search path. Right now I have

export PKG_CONFIG_PATH=$(find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//)

This works fine, but it does slow down my shell startup time, which now takes about 2 seconds. I'm sure that there's a better way built into homebrew, but I can't find it in the docs.

5

Convert the find to a static list colon : separated PKG_CONFIG_PATH list to reduce launch time.

Step 1. Run pkg-config --list-all to determine what packages are already know by

pkg-config --list-all

# tidy         tidy - tidy - HTML syntax checker
# tesseract    tesseract - An OCR Engine
# …    

Step 2. Run find to determine the pkgconfig directories that contain *.pc files.

# long form `find`
find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//)

# short form `find`
find / -name "pkgconfig" -print

# /usr/local/Cellar/abc/0.1.5/lib/pkgconfig:…/usr/local/Cellar/xyz/2.6/lib/pkgconfig

Step 3. Add the paths libraries of interest, that are not already discoverable by pkg-config, to PKG_CONFIG_PATH.

Option: use a /usr/local/Cellar/… path which will need to be updated with each version number change.

export PKG_CONFIG_PATH=/usr/local/Cellar/abc/0.1.5/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/Cellar/abc/0.1.5/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/my/build/from/source/mmmm/0.1.5/lib/pkgconfig

Options: When the Cellar is linked (typical) into /usr/local/opt/… then a version independent path can be found and used.

sudo find / -name "uvw" -print
# /usr/local/Cellar/uvw
# /usr/local/opt/uvw
ls -l /usr/local/opt/uvw
# /usr/local/opt/uvw@ -> ../Cellar/uvw/4.2_1
export PKG_CONFIG_PATH=/usr/local/opt/uvw/share/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opt/xyz/lib/pkgconfig
  • This is both beautiful and useful! Tyvm! – VladFr Jan 25 at 14:42
  • using /usr/local/opt/* is less likely to break when you upgrade homebrew packages vis a vis /usr/local/Cellar, IME. – hd1 Apr 29 at 17:44
  • 1
    @hd1 good point on using version independent links in path. Answer updated. – l --marc l Apr 29 at 20:45
0

I had a similar issue in Mac Mojave as /usr/include is gone under Xcode 10, and you have to install a separate package to get it back.

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

source: https://github.com/r-lib/xml2/issues/232

  • It's not clear to me how this answers the question.  If you believe that it does answer the question, please explain how it does so. … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. – Scott Feb 12 at 19:58

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.