Embed dynamic library and how to reference it

I have a dynamic library that I’ve dragged into my project as an asset, which - I assume - when built will end up embedded with the rest of my applications resources.

But, when I go to make an external method, I have to specify the Lib path. How can I tell it to use the location of the embedded library? What string would I use to reference the “resource” filename?

Follow-up: assuming I wanted multi-platform support, I assume I’d add all dynamic libraries and then create a constant that was a different string based on the platform and can reference that constant variable for the Lib instead?

Use a copy files script step instead of dragging the dylib into your project. Notarisation will freak out when the files aren’t in their proper places.

Make sure to use the Frameworks folder:

I use a constant to set the path to the library:

You can set different paths for different OSs.


@Beatrix_Willius this was very helpful. I didn’t know about the Copy File build steps and the @executable_path was knowledge I was missing as well. Thank you!

However, I still don’t yet seem to have it working. My hope is that there’s just one more piece of knowledge missing.


  • Copied the dylib file to the same directory as my Xojo project file;
  • Created the Copy File script and added the copied dylib file to it (I can r-click it and say “Show on Disk” and it takes me right to it next to the project file, so that seems fine).
  • Setup the copy script behaviors identical to what you have: Both, Any, Framework Folder.

However, when I build and open up the .app/Contents/Frameworks folder, the dylib file is not there.

I get no errors when building or running, but it also cannot find any of the external functions either, so my guess is that the Copy File script isn’t running and there’s one more little step I’m missing or I have it in the wrong location in my project somehow?

Thanks again.

Make sure that the dylib is copied also for debug:

Screenshot 2023-02-24 at 16.29.39

It is, hence the confusion. :wink:

Built Contents folder:


Another concern is that while I use the constant string for the Lib in the external methods, when I save the project (as text) and look at them, they still appear to be saved as strings:

#tag ExternalMethod, Flags = &h0
    Soft Declare Sub InitSystem Lib "LibPath" ()
#tag EndExternalMethod

Screenshot 2023-02-24 at 9.34.59 AM

It’s unclear if there’s something I need to do in order to tell it to use the constant instead of a string?

You’ve been very helpful, and I understand what it is to “debug” something you cannot see. I was hoping there was just some step I was missing like “enable Build Scripts in the project settings” or maybe this is some feature that requires a license a the Pro level or higher? But if - as described - it should just work, then I don’t know.

Typically constants in properties like that use # to indicate the constant name, rather than a fixed string of text. So Lib would be #LibPath. If the constant is in a different module or class then #ModuleName.LibPath.

Where does your Copy Files step exist in the Navigator (on the left)?
If it’s not after the “Build” step for macOS, it’s not actually being performed.

Those last two bits of information let everything fall into place and it’s working now. Thanks so much everyone!


1 Like