teltek / gst-plugin-ndi

GStreamer NDI Plugin for Linux
GNU Lesser General Public License v2.1
155 stars 27 forks source link

OSX / Catalina.. #52

Closed fairbairn closed 2 years ago

fairbairn commented 3 years ago

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?

sdroege commented 3 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.

Townsheriff commented 3 years ago

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.

sdroege commented 3 years ago

It would be useful to add something to the build.rs for setting this up automatically somehow for the different platforms.

zevarito commented 3 years ago

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"

normen commented 3 years ago

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.

fairbairn commented 2 years ago

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");
}