目的
Library not loaded: @rpath/libclang.dylib"
を解決する。
環境
- M1 Macbook Sonoma14.7.1
- cargo 1.83.0
- opencv: stable 4.11.0
エラー内容
cargo run
Blocking waiting for file lock on build directory
Compiling opencv v0.94.1
error: failed to run custom build command for `opencv v0.94.1`
Caused by:
process didn't exit successfully: `/Users/user/tests/fourier/target/debug/build/opencv-99c31a0adba7676d/build-script-build` (signal: 6, SIGABRT: process abort signal)
--- stderr
dyld[31167]: Library not loaded: @rpath/libclang.dylib
Referenced from: <804D229C-B191-3CCE-AB06-4C64F5AFBAC7> /Users/user/tests/fourier/target/debug/build/opencv-99c31a0adba7676d/build-script-build
Reason: tried: '/Users/user/tests/fourier/target/debug/deps/libclang.dylib' (no such file), '/Users/user/tests/fourier/target/debug/libclang.dylib' (no such file), '/opt/homebrew/Cellar/rust/1.83.0_1/lib/rustlib/aarch64-apple-darwin/lib/libclang.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/usr/lib//libclang.dylib' (no such file)
どうやら、opencvのbuild時に必要な動的ライブラリである
libclang.dylib
が見つかっていないようです。
手順
次のpathに着目しました。
/opt/homebrew/Cellar/rust/1.83.0_1/lib/rustlib/aarch64-apple-darwin/lib/libclang.dylib
ここの中で、libclang.dylibが見つかっていないようなのです。
stack overflow を探しましたところ、libclang.dylibは
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/
にあるようです。
$ ls /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/
AppIntentsMetadataExtractor.framework clang libcodedirectory.dylib swift
AppIntentsSupport.framework libIndexStore.dylib libswiftDemangle.dylib swift-5.0
LinkMetadataDT.framework libLTO.dylib libtapi.dylib swift-5.5
SwiftSourceKitClientPlugin.framework libSwiftDriver.dylib sourcekitd.framework swift_static
SwiftSourceKitPlugin.framework libclang.dylib sourcekitdInProc.framework tapi
$ ls /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ | grep "clang"
clang
libclang.dylib
そこで、libclang.dylibのシンボリックリンクを作成しました。
$ ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib /opt/homebrew/Cellar/rust/1.83.0_1/lib/rustlib/aarch64-apple-darwin/lib/libclang.dylib
ここで、もう一回 cargo runを実行
$ cargo run
Compiling opencv v0.94.1
Compiling fourier v0.1.0 (/Users/user/tests/fourier)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 27s
Running `target/debug/fourier`
Hello, world!
無事、buildされました。
参考