Closed fairbairn closed 2 years ago
The library needs to be in the library search path used by rustc
. You can set this via RUSTFLAGS="-L=/some/path
before compiling.
I managed to make it compile by adding these lines to build.rs
:
println!("cargo:rustc-link-lib=dylib=ndi");
println!("cargo:rustc-link-search=native=/System/Volumes/Data/Library/NDI SDK for Apple/lib/x64");
dynlib in /System/Volumes/Data/Library/NDI SDK for Apple/lib/x64 was called libndi.4.dynlib I renamed it to libndi.dynlib othewise it could not be found.
At this point I was able to compile.
Then I got runtime errors: Library not loaded: @rpath/libndi.4.dylib and to fix that I used install_name_tool -change @rpath/libndi.4.dylib "/System/Volumes/Data/Library/NDI_SDK_COPY/lib/x64/libndi.dylib" target/debug/libgstndi.dylib
And now I have no errors.
As for RUSTFLAGS="-L=/some/path
did not work, I think there is a typo also ("=" should be removed), but not an expert on this.
It would be useful to add something to the build.rs
for setting this up automatically somehow for the different platforms.
I've made it work like this, in both Mac & Linux:
RUSTFLAGS="-C link-args=-Wl,-rpath,/path-to-lib -L /path-to-lib -lndi"
The solution of @Townsheriff was the only one that worked for me to compile on mac. With the NDI SDK v5 the paths are slightly different (/Library/NDI SDK for macOS/lib/macOS
) but the dylib is called libndi.dylib
right out of the box. Still had to do the install_name_tool
step though.
With NDI 5, clean pull, my build.rs ended up as @Townsheriff suggested, and it compiled..
fn main() {
gst_plugin_version_helper::info();
println!("cargo:rustc-link-lib=dylib=ndi");
println!("cargo:rustc-link-search=native=/System/Volumes/Data/Library/NDI SDK for Apple/lib/x64");
}
Base code compiles fine under rust, however when linking, it cannot resolve the NDI related references.
Installing the NDI SDK for Mac provides their libndi.4.dylib for x64 but not as a statically linkable option.
I've tried setting LIBRARY_PATH, moving the dylib around, but I feel the compilation is likely looking for a static library to link with.
Any hints on how this might be compiled to work on Mac?