Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDExtension not load dependencies dll in Editor #91004

Open
CsloudX opened this issue Apr 22, 2024 · 1 comment
Open

GDExtension not load dependencies dll in Editor #91004

CsloudX opened this issue Apr 22, 2024 · 1 comment

Comments

@CsloudX
Copy link

CsloudX commented Apr 22, 2024

Tested versions

v4.3.dev5.mono.official [89f70e9]

System information

Godot v4.3.dev5.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 5GB (NVIDIA; 31.0.15.3623) - AMD Ryzen 9 3900X 12-Core Processor (24 Threads)

Issue description

I'm try write a gdextension, and in my gdextension dll(libgdexample.windows.template_debug.x86_64.dll), I load a dependencies dll (EthutilErpc.dll), for test, when load_dll(EthutilErpc.dll) failed, print a error msg.
image

And the gdexample.gdextension like this:

[configuration]

entry_symbol = "example_library_init"
compatibility_minimum = "4.1" 

[libraries]
windows.debug.x86_64 = "libgdexample.windows.template_debug.x86_64.dll"
windows.release.x86_64 = "libgdexample.windows.template_release.x86_64.dll"

[dependencies]
windows.x86_64 = { 
	"EthutilErpc.dll": "", 
	"ftd2xx.dll": ""
}

And I'm put all the dlls in my EthutilErpcDLL folder:
image

when export, everything was OK (the dependencies dlls auto copyed and exe run correct with dll).
image
image

But in Editor, it can't load the EthutilErpc.dll:
image
(This error info print by)
image
image

Steps to reproduce

above

Minimal reproduction project (MRP)

demo.zip

ADDITION: In Editor, if i copy EthutilErpc.dll to project root folder, it can work correct.

@dsnopek
Copy link
Contributor

dsnopek commented Jun 13, 2024

Loading dependencies is the responsibility of the extension itself - Godot doesn't do anything to assist with that. The [dependencies] section in .gdextension files is only for copying the dependencies into the requested location on export.

I'm not an expert on Windows, but I think the problem is that the Windows dynamic linker looks in the same directory as the executable by default. I think you need to tell it to search in the same directory as your extension. In godot-cpp, you can do something like this to get the path to your extension (untested):

godot::String path;
godot::internal::gdextension_interface_get_library_path(godot::internal::library, path._native_ptr());

Per Google, I found that there is a SetDllDirectory() function in the Windows API. You may be able to do something like (untested):

SetDllDirectory(path.get_base_dir().to_wchar_buffer().ptr());

Hopefully that helps you figure it out!

In any case, this is something for the extension to handle itself, and isn't a bug in Godot.

@dsnopek dsnopek added this to the 4.x milestone Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants