Skip to content

Linking on macOS is still troublesome #34

@vrmiguel

Description

@vrmiguel

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/github.com-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions