Can't get GDNative plugin to load

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By imekon

I’ve created a native C++ plugin with the Godot toolkit and I’m getting errors loading the DLL:

ERROR: Can't open dynamic library: D:/samples/godot/godot-unofficial-demo-projects-v3/td2/bin/libclipper.dll. Error: Error 193: %1 is not a valid Win32 application.
At: platform\windows\os_windows.cpp:1687
ERROR: GDNative::get_symbol: No valid library handle, can't get symbol from GDNative object
At: modules\gdnative\gdnative.cpp:315
ERROR: NativeScriptLanguage::init_library: No nativescript_init in "res://bin/libclipper.dll" found
At: modules\gdnative\nativescript\nativescript.cpp:1054

This is Godot V3.0.2 64 bit so why it talking about 32 bit application?
I can see with dependency walker that godot_nativescript_init is present, so it’s not finding it for some reason.

All I did is switch the C sample to C++ and put extern “C” on three functions

godot_nativescript_init
godot_gdnative_init
godot_gdnative_terminate

So what am I doing wrong?

I encountered the exact same problem. I think it was related to compiler settings. I can try to find the problem later today.

Edit: I can’t seem to reproduce it, sorry.

Akorian | 2018-05-23 10:57

:bust_in_silhouette: Reply From: imekon

I tried again on a different machine - this time I used a different version of vcvarsall.bat to setup Visual Studio for C++ compilation.

vcvars64

Now it runs just fine and I’m not seeing the errors I did before!

hello, i’m running in the same problem…
is it the file you are talking about?
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat ?

frankiezafe | 2018-12-15 19:50

just tried and it worked!!! thanks a thousand times for this post!

frankiezafe | 2018-12-15 20:01

you really help me a lot.the same error and use your methoid now i cam compile successfully. and i find that the original vcvars is x86_64, and after i used your method it changed to x64, , so i guess this is the erroe caused by win32 or x86? hoping someone can find the real reason of this. thanks again.

zhaishengfu | 2019-06-20 14:49

Yes, this works. You need to run the Visual Studio Developer Command Prompt, go to the folder containing vcvars64.bat and run it. In my case, the folder was:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat

Then compile and link simple.c as found in the instructions.

Also make sure that your simple.gdns class name is all caps: SIMPLE. Any lower case letters made it not work for me.

Note that using the other Visual Studio command prompts (for example, x64 Native Tools Command Prompt), as suggested by the Visual Studio website, didn’t work for me.

JeremiahLR | 2019-11-01 01:57

thanks works for me too! with VS 2019, as for the detailed reason i saw this helped quite a lot building-on-the-command-line

in short, we must use that specific x64 architecture to compile. Also to make things fast in the future use, try to make x64 easy to execute from developer command prompt. By using this command first vcvarsall [architecture] in my case its vcvarsall x64. Add vcvarshall.bat to your PATH.

untimated | 2022-02-23 00:50