Reputation: 584
I'm new to macOS, and I'm having trouble using the library libjpeg.
After installing with brew install jpeg, I even tried reinstalling.
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
🍺 /opt/homebrew/Cellar/jpeg/9d: 21 files, 1001.2KB
Then I try to see if I can find the library, I type the following command in terminal: "gcc -ljpeg". This gives output below:
ld: library not found for -ljpeg
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why can't it find the library? And what can I do to fix the installation? Am I even using these terminal commands correctly?
EDIT: I managed to find the symlink (.dylib) under /opt/homebrew/Cellar/jpeg/9d/lib. But when I ran gcc -ljpeg -L /opt/homebrew/Cellar/jpeg/9d/lib/, I get the following error message:
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Upvotes: 4
Views: 5535
Reputation: 134
Thanks for the response.. Sadly that specific suggestion made no difference..
However I did some playing and I did get it to work by forcing the AC_CHECK_HEADERS checks to "yes" for jpeg and libmicrohttpd
AC_CHECK_HEADERS(setjmp.h jerror.h jpeglib.h,[JPGS="yes"],[JPGS="yes"])
and
AC_CHECK_HEADERS(microhttpd.h,[MHTTP="yes"],[MHTTP="yes"])
The configure was successful and motion has compiled by overriding the checks to force them to succeed.
It appears that the AC_CHECK_HEADERS on macOS 12.4 M1 is broken.
Upvotes: 1
Reputation: 21
Using cmake and this command helped me:
cmake -DJPEG_LIBRARY_RELEASE=/opt/homebrew/Cellar/jpeg/9e/lib/libjpeg.a
Upvotes: 1
Reputation: 111
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
Upvotes: 5
Reputation: 584
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
Since I'm using this library for an Xcode project, I just had to add this path + /lib/ to my library search paths in Xcode, and it was able to find the library.
Upvotes: 2