Hi,

I have recently started to create my first GDExtension on MacOS. I had success in following the tutorial and got it working in the editor, but I began to run into troubles when I tried to import a third party .dylib.
I had success compiling my C++ by importing the library like so.

env.Append(CPPPATH=["src/"], LIBPATH = ['/usr/lib', '/usr/local/lib'], LIBS = ['angelscript'])

But when I opened up my Godot project I was getting an error that basically told me that it was searching in "usr/lib" for my .dylib file but was unable to find it. I found this odd as my .dylib file is in "usr/local/lib", but I wasn't able to figure out a way to point Godot in the right direction. Does anyone know how I may be able to solve this? I tried a bit of fiddling with the .gdextension file but perhaps I don't have a good understanding of how it works (and I tried googling for solutions but I wasn't able to find anything that worked). Thank you.

    amiicli Put all dependency runtime libraries into the same directory your compiled extension runtime library is.

    amiicli use the OS class and look at the docs:
    https://docs.godotengine.org/en/stable/classes/class_os.html

    https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html

    Converting paths to absolute paths or "local" paths

    You can use ProjectSettings.globalize_path() to convert a "local" path like res://path/to/file.txt to an absolute OS path. For example, ProjectSettings.globalize_path() can be used to open "local" paths in the OS file manager using OS.shell_open() since it only accepts native OS paths.

    To convert an absolute OS path to a "local" path starting with res:// or user://, use ProjectSettings.localize_path(). This only works for absolute paths that point to files or folders in your project's root or user:// folders.

    Thank you, I tried placing my dynamic library in the bin folder but that did not work for me unfortunately, even after pointing to it with [dependencies] in the .gdextension file.
    I'm sorry but I didn't really know what to do with the the OS class suggestion, how can I use that to find the dynamic library?

    Right now I'm getting these errors in the Godot console
    Can't open dynamic library: /*pathtoproject*/*Godot Project Folder*/bin/libgdexample.macos.template_debug.framework. Error: dlopen(/*pathtoproject*/*Godot Project Folder*/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug, 0x0002): Library not loaded: '@rpath/libangelscript.2.37.0.dylib'

    It goes on to state that the reason is that it can't find the .dylib file in my Godot.app/Contents or in /usr/lib/

    • xyz replied to this.

      amiicli What setup did you use to build the extension? Scons or something else?

        xyz I used scons, and the compile worked with no errors

        I found the fix!
        I had to use the LINKFLAGS argument in the SConstruct file as so:
        env.Append(LINKFLAGS=['-arch', 'arm64', '-rpath', '/usr/local/lib/'])
        Now it points to my usr/local/lib directory which solved the errors.
        Granted, now my node is crashing but I feel that's a different problem than what I specified in the OP.

        • xyz replied to this.

          amiicli For an extension, it's better to use a relative rpath if you intend to export and distribute those runtimes with your game. Use $ORIGIN token to specify the current directory of the executable i.e. your extension. So if the extension runtime is in bin and you copy the dependencies into bin/dependencies you can set rpath to $ORIGIN/dependencies. Try it out and see if it works.