Copy link to clipboard
Copied
Hello All,
So after using the much appreciated help here on the forums, I was successful at loading a third-party DLL that I needed to use in my plugin on Windows. Now, I'm moving onto OSX and have a .dylib file that is effectively the equivalent of the DLL in OSX. My question is how do I properly load the .dylib on OSX for my plugin to work within AE?
Many thanks for your time and help!
Best,
Arie
Ah, ok, that should make things easier. So where did you put your dylib file? Same as with Windows, it needs to be in a location referenced in the path environment variable or in the location of the calling application. Easiest thing to test will probably if you put it in /usr/lib or /usr/local/lib (for global access) or ~/lib for the current user only.
See also here: Using Dynamic Libraries
Copy link to clipboard
Copied
Hi Arie,
well, it depends on how much you know already and where you are having problems. 🙂
A .dylib is basically nothing more than a renamed .so (shared object) object file from the Linux world
The equivalent command for "LoadLibrary" on MacOS is "dlopen", and you can access function pointers/symbols with "dlsym", and instead of "FreeLibrary" you use "dlclose".
Check these links for some info:
Dynamic loading - Wikipedia, the free encyclopedia
OS X ABI Dynamic Loader Reference‌
http://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-osx
Copy link to clipboard
Copied
But how do you reference the .dylib file? Do we just include it in the bundle of the plugin and reference it somehow from there?
Copy link to clipboard
Copied
That is the same situation as on Windows with a Dll
You can deploy the dylib as part of your bundle / plugin (which is a folder anyway) or in any other common folder, then use the path function from the sdk that I posted in the other thread to determine the path and put that full path into dlopen.
Copy link to clipboard
Copied
Many thanks for your guidance and time, Toby! I will get to it and post back with results.
Copy link to clipboard
Copied
I took a look at the links you sent, but I still do not understand how to actually make the call to the function in the dynamic library.
so far i have something like:
void* extLibrary;
void* libFunction;
extLibrary = dlopen("/Library/Application Support/MyApp/extLib.dylib");
libFunction = dlsym(extLibrary, "my_fancy_function");
What I don't understand is how to actually call the function in the dynamic library and how do I pass parameter values to that function?
Copy link to clipboard
Copied
I assume you know the syntax of the function to be called?
If so, just cast the void pointer you get from dlsym() to a function pointer matching the declaration of your desired function.
Basically the same stuff as on Windows with LoadLibrary()
Here is a simple example with 2 int params:
typedef void (*my_fancy_function_type)(int, int);
my_fancy_function = (my_fancy_function_type)libFunction;
// now you can call your function:
my_fancy_function(12, 34);
Copy link to clipboard
Copied
All of this code above applies however only if you want to load a .dylib at runtime and dynamically load a function from it.
If you don't need runtime loading, there is also (just like on Windows with lib+dll) the option to link directly to the .dylib from within Xcode, then you only need the header file for the declaration and a path to the .dylib in the Xcode library settings.
Copy link to clipboard
Copied
I don't need it at runtime, but I was getting the same error from AE about my plugin being invalid. I essentially added the .dylib file to the list of dynamic libraries under the "Link Binary With Libraries" heading in the "Build Phases" tab of my bundle target. Then I added the path to the .dylib file under the "Library Search Paths" setting under the "Build Settings" tab of my target.
I do have a header file for the .dylib, and I placed it in my plugin's code. XCode built the plugin successfully, but when I went to apply it on a layer in AE, it just gave me an error that said "Could not find entry point", then it said "Invalid Filter". So, that was the same error I was receiving on the windows side. Is there anything I'm missing to make sure the .dylib loads correctly if I don't want to do run time loading?
Copy link to clipboard
Copied
Ah, ok, that should make things easier. So where did you put your dylib file? Same as with Windows, it needs to be in a location referenced in the path environment variable or in the location of the calling application. Easiest thing to test will probably if you put it in /usr/lib or /usr/local/lib (for global access) or ~/lib for the current user only.
See also here: Using Dynamic Libraries
Copy link to clipboard
Copied
Toby,
You're amazing! Thank you for your help on this and for your mentorship. It works now on OSX.
—Arie
Find more inspiration, events, and resources on the new Adobe Community
Explore Now