PKG_CONFIG_PATH 中的 Homebrew 软件包

PKG_CONFIG_PATH 中的 Homebrew 软件包

我使用 homebrew 安装了许多库,但我不知道如何将它们放入 pkg-config 的搜索路径中。目前我有

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

这很好用,但它确实减慢了我的 shell 启动时间,现在大约需要 2 秒。我确信 homebrew 中内置了更好的方法,但我在文档中找不到它。

答案1

将其转换find为以冒号分隔的静态列表:PKG_CONFIG_PATH 列表以减少启动时间。

步骤 1. 运行pkg-config --list-all以确定哪些包已经被

pkg-config --list-all

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

步骤2.运行find确定pkgconfig包含*.pc文件的目录。

### long form `find`
find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//
find /usr/local/Cellar -name 'pkgconfig' -type d | grep share/pkgconfig | tr '\n' ':' | sed s/.$//
# - or -
find /usr/local/Cellar -name 'pkgconfig' -type d | grep 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

步骤 3. 添加感兴趣的路径库,尚未被发现pkg-config,到 PKG_CONFIG_PATH。

选项:使用/usr/local/Cellar/…随着每次版本号改变而需要更新的路径。

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

选项:当 Cellar 链接到(通常)时,/usr/local/opt/…可以找到并使用独立于版本的路径。

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

注意:Apple ARM 和 Apple Intel 有不同的自制Cellar位置。

  • 苹果 ARM:/opt/homebrew/Cellar
  • 苹果英特尔:/usr/local/Cellar

答案2

/usr/include我在 Mac Mojave 上也遇到了类似的问题在 Xcode 10 下消失,您必须安装单独的包才能将其恢复。

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

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

相关内容