I am trying to load a library(say ArithmeticOprn.dylib) dynamically and call the methods presented within that library. Please refer to the sample code snippet from below,
[DllImport("libdl.dylib")]
public static extern IntPtr dlopen(String fileName, int flags);
[DllImport("ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
static void Main(string[] args)
{
dlopen("path/to/ArithmeticOprn.dylib", 2);
double result = Add(1, 2);
}
While running the above sample in MacOS, I got the following exception:
Unable to load DLL "ArithmeticOprn.dylib": The specified module or one of its dependencies could not be found.
But, when I provide full path in the DllImport the method call works and I can get the expected results. For your reference, please refer below for the code snippet.
[DllImport("path/to/ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
Could you please let me know what I am missing ? Thanks in advance :)
otool -L
(this is the (kind of) OSXs equivalent for ldd) on your lib, and check which dependencies are not found and why. Could be that they are present, but they target a different architecture. – Tomasz