Macos 找不到libjpeg的安装

Macos 找不到libjpeg的安装,macos,libjpeg,Macos,Libjpeg,我是macOS新手,在使用libjpeg库时遇到问题 使用brew install jpeg安装后,我甚至尝试重新安装 joshbone@Joshs-Mac-mini ~ % brew reinstall jpeg ==> Downloading https://homebrew.bintray.com/bottles/jpeg-9d.arm64_big_sur.bottl Already downloaded: /Users/joshbone/Library/Caches/Homebre

我是macOS新手,在使用libjpeg库时遇到问题

使用brew install jpeg安装后,我甚至尝试重新安装

joshbone@Joshs-Mac-mini ~ % brew reinstall jpeg
==> Downloading https://homebrew.bintray.com/bottles/jpeg-9d.arm64_big_sur.bottl
Already downloaded: /Users/joshbone/Library/Caches/Homebrew/downloads/12e480d7337641afc99230ff2b626197e3206ea378eef8ccbb8b11f587afe7f4--jpeg-9d.arm64_big_sur.bottle.tar.gz
==> Reinstalling jpeg 
==> Pouring jpeg-9d.arm64_big_sur.bottle.tar.gz
Why can't it find the library?

It either doesn't exist or isn't in the include path.

And what can I do to fix the installation?

Use the
-v
flag as gcc suggests (
gcc -ljpeg -v
). You'll see a
-L
flag and that will tell you where it's looking for library files (the include path). In my case it's
-L/usr/local/lib
and if I look in that directory for "jpeg" (
ls /usr/local/lib/ | grep jpeg
) I see
libjpeg.dylib
is there.

brew by default installs to
/usr/local/Cellar
on Intel or
/opt/homebrew
on ARM (hereby referred to as
<prefix>
). The file
<prefix>/jpeg/9d/lib/libjpeg.dylib
should exist and brew should have created
/usr/local/lib/libjpeg.dylib
as a symlink to the installed version. Potentially brew isn't creating that symlink like it's supposed to. Running
brew doctor
may offer some insight or you could manually create that symlink but without knowing more you may run into this issue with other libraries.

Another option is to tell gcc to look in the path brew says it installed libjpeg to:
gcc -v -ljpeg -L <prefix>/jpeg/9d/lib/
. Which would obviously break other libraries but it lets us know that library will actually run.

And it never hurts to check permissions.

Am I even using these terminal commands correctly?

Yes. I tested with a fresh install of Mojave. I ran
gcc -ljpeg
and got the same error as you. Then I ran
brew install jpeg
and then
gcc -ljpeg
returns what you would expect (
undefined symbols [...] "_main"
)

In some cases the headers are bundled separately and you'll install something like
brew install package-dev
but they're bundled with the
jpeg
package.

Since you're new to MacOS, I frequently run into quirks using it for development. It's nowhere near the frustration of developing on Windows but the best way to utilize MacOS for development is to ssh into a Linux box imo

I was able to find the installation path by trying to uninstall the library.

I ran "brew uninstall jpeg", and it refused to install because of dependencies, but the first line of the error message gave me the path to look in.

Error: Refusing to uninstall /opt/homebrew/Cellar/jpeg/9d
joshbone@Joshs-Mac mini~%brew重新安装jpeg
==>下载https://homebrew.bintray.com/bottles/jpeg-9d.arm64_big_sur.bottl
已下载:/Users/joshbone/Library/Caches/Homebrew/downloads/12e480d7337641afc99230ff2b626197e3206ea378eef8ccbb8b11f587afe7f4--jpeg-9d.arm64_big_sur.ball.tar.gz
==>重新安装jpeg
==>倾倒jpeg-9d.arm64_big_sur.瓶子.tar.gz
为什么它找不到图书馆

它不存在或不在包含路径中

我能做些什么来修复安装

按照gcc的建议使用
-v
标志(
gcc-ljpeg-v
)。您将看到一个
-L
标志,它将告诉您它在哪里查找库文件(包含路径)。在我的例子中,它是
-L/usr/local/lib
,如果我在那个目录中查找“jpeg”(
ls/usr/local/lib/| grep jpeg
),我会看到
libjpeg.dylib

brew默认安装在英特尔上的
/usr/local/cillar
,或ARM上的
/opt/homebrew
(以下简称
)。文件
/jpeg/9d/lib/libjpeg.dylib
应该存在,brew应该已经创建了
/usr/local/lib/libjpeg.dylib
作为安装版本的符号链接。brew可能不会像预期的那样创建该符号链接。运行
brew doctor
可能会提供一些见解,或者您可以手动创建该符号链接,但在不了解更多信息的情况下,您可能会在其他库中遇到此问题

另一个选项是告诉gcc查看brew所说的libjpeg安装路径:
gcc-v-ljpeg-L/jpeg/9d/lib/
。这显然会破坏其他库,但它让我们知道库将实际运行

检查权限也不会有什么坏处

我是否正确使用了这些终端命令

对。我用新安装的莫哈韦进行了测试。我运行了
gcc-ljpeg
,得到了与您相同的错误。然后我运行了
brew安装jpeg
,然后
gcc-ljpeg
返回您期望的结果(
未定义的符号[…]”“\u main”

在某些情况下,头是单独捆绑的,您将安装类似于
brew安装包dev
的东西,但它们与
jpeg
包捆绑在一起

由于您是MacOS新手,我经常在使用它进行开发时遇到一些怪癖。在Windows上进行开发远没有遇到挫折,但利用MacOS进行开发的最佳方法是将ssh连接到Linux机箱中

为什么它找不到图书馆

它不存在或不在包含路径中

我能做些什么来修复安装

按照gcc的建议使用
-v
标志(
gcc-ljpeg-v
)。您将看到一个
-L
标志,它将告诉您它在哪里查找库文件(包含路径)。在我的例子中,它是
-L/usr/local/lib
,如果我在那个目录中查找“jpeg”(
ls/usr/local/lib/| grep jpeg
),我会看到
libjpeg.dylib

brew默认安装在英特尔上的
/usr/local/cillar
,或ARM上的
/opt/homebrew
(以下简称
)。文件
/jpeg/9d/lib/libjpeg.dylib
应该存在,brew应该已经创建了
/usr/local/lib/libjpeg.dylib
作为安装版本的符号链接。brew可能不会像预期的那样创建该符号链接。运行
brew doctor
可能会提供一些见解,或者您可以手动创建该符号链接,但在不了解更多信息的情况下,您可能会在其他库中遇到此问题

另一个选项是告诉gcc查看brew所说的libjpeg安装路径:
gcc-v-ljpeg-L/jpeg/9d/lib/
。这显然会破坏其他库,但它让我们知道库将实际运行

检查权限也不会有什么坏处

我是否正确使用了这些终端命令

对。我用新安装的莫哈韦进行了测试。我运行了
gcc-ljpeg
,得到了与您相同的错误。然后我运行了
brew安装jpeg
,然后
gcc-ljpeg
返回您期望的结果(
未定义的符号[…]”“\u main”

在某些情况下,头是单独捆绑的,您将安装类似于
brew安装包dev
的东西,但它们与
jpeg
包捆绑在一起


由于您是MacOS新手,我经常在使用它进行开发时遇到一些怪癖。在Windows上进行开发远没有遇到挫折,但利用MacOS进行开发的最佳方法是将ssh连接到Linux机箱中。我通过尝试卸载库找到了安装路径

我运行了“brew uninstall jpeg”,由于依赖关系,它拒绝安装,但错误消息的第一行给出了查找路径


由于我将此库用于Xcode项目,我只需将此路径+/lib/添加到Xcode中的库搜索路径中,它就能够找到库。

我可以通过尝试卸载库来找到安装路径

我运行了“brew uninstall jpeg”,由于依赖关系,它拒绝安装,但错误消息的第一行给出了查找路径


由于我在Xcode项目中使用这个库,我只需将这个路径+/lib/添加到我在Xcode中的库搜索路径中,它就能够找到库。

尝试添加
-L/usr/local/lib
尝试添加
-L/usr/local/lib
我的路径/usr/local/似乎是空的,所以它不包含“酒窖”子目录I仔细查看了您最初问题的输出,brew正在安装到/opt/homebrew,因此您必须拥有ARM处理器Mac。检查jpeg包的/opt/homebrew目录,并运行
brew link jpeg
以触发链接