安装 Gem phashion 时出错:ld: 找不到 -ljpeg 的库

Error when installing Gem phashion: ld: library not found for -ljpeg

当我在我的 gemfile 中使用 Pashion 捆绑安装我的项目时。

我遇到故障排除: ld: library not found for -ljpeg.

已确认我已通过以下命令安装 jpeg, libjpeg, libpng
brew install jpegbrew install libjpeg
brew install libpng

gem install phashion -v '1.2.0' 会得到同样的错误。

Machine: MacBook Air (M1, 2020)
Os: macOS BigSur 11.2 (20D64)

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Related:
I use homebrew, which has full support on NEW Mac(M1), to install pacakges.
I use rvm(1.29.12) to manage ruby(2.6.3 as default).

最喜欢这里的问题https://github.com/westonplatter/phashion/issues/19

经过多方查找和尝试,解决方案如下:

  1. gem install phashion -v '1.2.0'
    您将得到故障排除:ld: library not found for -ljpeg

  2. 使用配置安装 phashion
    LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/opt/libjpeg/lib gem install phashion -v '1.2.0'
    然后你会得到故障排除:fatal error: 'jpeglib.h' file not found

  3. 上次排查是因为clang路径错误。所以
    export CPLUS_INCLUDE_PATH=/opt/homebrew/include 添加到 ~/.zshrc
    别忘了 source ~/.zshrc.

  4. 运行 LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/opt/libjpeg/lib gem install phashion -v '1.2.0' 再一次。
    然后您将得到故障排除:ld: library not found for -lpng

  5. 运行 LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/opt/libjpeg/lib:/opt/homebrew/opt/libpng/lib gem install phashion -v '1.2.0' 再一次。

安装成功!