Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking on macOS is still troublesome #34

Open
vrmiguel opened this issue Jan 19, 2023 · 2 comments
Open

Linking on macOS is still troublesome #34

vrmiguel opened this issue Jan 19, 2023 · 2 comments
Labels

Comments

@vrmiguel
Copy link

Hey there! I'm trying to use magic-sys on an app of mine but I'm having some issues compiling on macOS

Versions

$ uname -mv 
Darwin Kernel Version 21.6.0: Thu Sep 29 20:13:46 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T8101 arm64
$ brew link libmagic
Warning: Already linked: /opt/homebrew/Cellar/libmagic/5.44
$ rustc --version
rustc 1.68.0-nightly (92c1937a9 2022-12-27)

and magic-sys 0.3.0

Build outputs

When running cargo build

ld: library not found for -lmagic

When running MAGIC_DIR=/opt/homebrew/Cellar/libmagic/5.44/lib MAGIC_STATIC=false cargo run

  thread 'main' panicked at 'No libmagic.so found in "/opt/homebrew/Cellar/libmagic/5.44/lib"', /Users/viniciusmiguel-mba/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/magic-sys-0.3.0/build.rs:30:21

It seems build.rs still only looks for libmagic.so instead of libmagic.dylib on macOS, which causes the build to fail, despite #32

If I go to /opt/homebrew/Cellar/libmagic/5.44/lib and symlink libmagic.dylib to libmagic.so then it works correctly

When running MAGIC_DIR=/opt/homebrew/Cellar/libmagic/5.44/lib MAGIC_STATIC=true cargo run

  = note: Undefined symbols for architecture arm64:
            "_BZ2_bzDecompress", referenced from:
                _uncompressbzlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_BZ2_bzDecompressEnd", referenced from:
                _uncompressbzlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_BZ2_bzDecompressInit", referenced from:
                _uncompressbzlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_inflate", referenced from:
                _uncompresszlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_inflateEnd", referenced from:
                _uncompresszlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_inflateInit2_", referenced from:
                _uncompresszlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_inflateInit_", referenced from:
                _uncompresszlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
            "_zError", referenced from:
                _uncompresszlib in libmagic_sys-1608e149fbcfc5d0.rlib(compress.o)
          ld: symbol(s) not found for architecture arm64
@robo9k
Copy link
Owner

robo9k commented Jan 19, 2023

For libmagic.dylib there's #30 which I didn't get to merge yet.

As for why libmagic is not found with just cargo build I'm not sure. I don't have a Mac, so can't really test how Brew behaves, especially on arm64. I can experiment by using GitHub Actions for this (see .github/workflows/mac.yml) but this is a bit cumbersome.
Can you check if the Brew directories are included in the default ld library paths?

The undefined symbols might be solved with using pkg-config, see #1
Could you check whether Brew installed a libmagic.pc or such and post it?
This might be a similar case as #16 (comment) and #30 (comment)

@robo9k
Copy link
Owner

robo9k commented Jan 19, 2023

Could you elaborate why you got your own wizardry binding instead of using the/my magic crate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants