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

3
当我在我的Gemfile中使用Pashion并执行bundle install时,出现了以下故障: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个回答

8

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

  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路径错误导致的。所以
    ~/.zshrc文件中添加export CPLUS_INCLUDE_PATH=/opt/homebrew/include
    别忘了执行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'

安装成功!


谢谢。我刚刚转换到了M1机器,并在设置rails时遇到了这个问题。我还不得不解决这个问题:https://dev59.com/r1EG5IYBdhLWcg3wVqz9 - Rych
M1 Pro机器在这里。运行得非常好! - Piotr Usewicz
这个代码可以正常运行,但是当phashion gem在gemfile中定义时,该怎么做呢?当我运行Bundler时,环境变量似乎不起作用。 - ntocampos
谢谢,这些对我来说也是缺失的拼图(在M1 Mac上)。 - Pirkka Esko
我在使用 CPLUS_INCLUDE_PATH 时遇到了一些问题。它似乎无法正常工作,即使我将它放入我的 .zshrc 文件并进行了源化,我仍然会收到 “致命错误:找不到‘jpeglib.h’文件”的提示。还有别的人遇到这个问题吗? - Aurel Drejta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接