Trouble with the GDNative C++ example from the documentation.

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

Godot is an awesome engine but it strongly resists to the easy use of any other language but gdscript that I’m not so fond of. To the point:

Trying to get the GDNative C++ tutorial from the official documentation to compile (GDNative C example — Godot Engine (3.2) documentation in English) but I get some link errors that I can’t figure out how to solve. First time using scons. The api and the bin library generation went fine. The problems start when trying to compile the plugin. Maybe something wrong with my directory structure? I took a look at the SConstruct file though and all paths seem fine.

D:_Gamedev\Godot\Projects\game>scons platform=windows
scons: Reading SConscript files …
scons: done reading SConscript files.
scons: Building targets …
link /nologo -DEBUG /dll /out:game\bin\win64\libgdexample.dll /implib:game\bin\win64\libgdexample.lib /LIBPATH:godot-cpp\bin libgodot-cpp.windows.debug.64.lib src\gdexample.obj src\gdlibrary.obj
Creating library game\bin\win64\libgdexample.lib and object game\bin\win64\libgdexample.exp
gdexample.obj : error LNK2019: unresolved external symbol “public: __thiscall godot::Variant::Variant(class godot::Variant const &)” (??0Variant@godot@@QAE@ABV01@@Z) referenced in function “public: void __thiscall godot::_WrappedMethod<class godot::GDExample,void,float>::apply<0>(class godot::Variant *,class godot::GDExample *,class godot::Variant * *,struct godot::__Sequence<0>)” (??$apply@$0A@@?$_WrappedMethod@VGDExample@godot@@XM@godot@@QAEXPAVVariant@1@PAVGDExample@1@PAPAV21@U?$__Sequence@$0A@@1@@Z)
gdexample.obj : error LNK2019: unresolved external symbol "public: __thiscall godot::Variant::operator float(void)const " (??BVariant@godot@@QBEMXZ) referenced in function “public: static float __cdecl godot::_ArgCast::_arg_cast(class godot::Variant)” (?_arg_cast@?$_ArgCast@M@godot@@SAMVVariant@2@@Z)
gdexample.obj : error LNK2019: unresolved external symbol “public: __thiscall godot::Variant::~Variant(void)” (??1Variant@godot@@QAE@XZ) referenced in function “public: static float __cdecl godot::_ArgCast::_arg_cast(class godot::Variant)” (?_arg_cast@?$_ArgCast@M@godot@@SAMVVariant@2@@Z)
gdexample.obj : error LNK2019: unresolved external symbol “public: void __thiscall godot::Node2D::set_position(struct godot::Vector2)” (?set_position@Node2D@godot@@QAEXUVector2@2@@Z) referenced in function “public: void __thiscall godot::GDExample::_process(float)” (?_process@GDExample@godot@@QAEXM@Z)
gdexample.obj : error LNK2001: unresolved external symbol _api
gdexample.obj : error LNK2001: unresolved external symbol _nativescript_api
gdlibrary.obj : error LNK2001: unresolved external symbol _nativescript_api
gdexample.obj : error LNK2001: unresolved external symbol “public: static void * godot::_RegisterState::nativescript_handle” (?nativescript_handle@_RegisterState@godot@@2PAXA)
gdlibrary.obj : error LNK2001: unresolved external symbol “public: static void * godot::_RegisterState::nativescript_handle” (?nativescript_handle@_RegisterState@godot@@2PAXA)
gdlibrary.obj : error LNK2019: unresolved external symbol “public: static void __cdecl godot::Godot::gdnative_init(struct godot_gdnative_init_options *)” (?gdnative_init@Godot@godot@@SAXPAUgodot_gdnative_init_options@@@Z) referenced in function _godot_gdnative_init
gdlibrary.obj : error LNK2019: unresolved external symbol “public: static void __cdecl godot::Godot::gdnative_terminate(struct godot_gdnative_terminate_options *)” (?gdnative_terminate@Godot@godot@@SAXPAUgodot_gdnative_terminate_options@@@Z) referenced in function _godot_gdnative_terminate
gdlibrary.obj : error LNK2019: unresolved external symbol “public: static void __cdecl godot::Godot::nativescript_init(void *)” (?nativescript_init@Godot@godot@@SAXPAX@Z) referenced in function _godot_nativescript_init
gdlibrary.obj : error LNK2019: unresolved external symbol “void __cdecl godot::_TagDB::register_type(unsigned int,unsigned int)” (?register_type@_TagDB@godot@@YAXII@Z) referenced in function “void __cdecl godot::register_class(void)” (??$register_class@VGDExample@godot@@@godot@@YAXXZ)
gdlibrary.obj : error LNK2001: unresolved external symbol _nativescript_1_1_api
libgodot-cpp.windows.debug.64.lib : warning LNK4272: library machine type ‘x64’ conflicts with target machine type ‘x86’
game\bin\win64\libgdexample.dll : fatal error LNK1120: 12 unresolved externals
scons: *** [game\bin\win64\libgdexample.dll] Error 1120
scons: building terminated because of errors.

Okay, I wrote a simple non-agnostic SConstruct and managed to build it. I guess the SCostruct provided with the tutorial is messed up.

KoukouStudios | 2020-03-21 20:54

Please report this on the Godot documentation repository :slight_smile:

Calinou | 2020-03-24 09:17

:bust_in_silhouette: Reply From: Paul Grad

I ran into the same issue, and I actually pinned the problem down to cl.exe itself.
There are different builds of cl.exe for different architectures, including a x86 build and a x64 build. You can find out what arch your cl.exe is using by doing “where cl.exe”. I had a x86 build of cl.exe.

I switched to the x64 Native Tools Command Prompt for VS2019 and did a scons build from that prompt and the link errors went away, resulting in a successful build.

Oh my god I’ve been trying to build all day, this ended up being the answer for me lol. Didn’t even realize I had a x86 version of Visual Studio’s command prompt

andrewpratt64 | 2021-06-26 06:04

same problem, but luckily acrossed the same problem before in this post

untimated | 2022-02-24 01:13

I had this problem too. I just had to change my Windows PATH Environmental Variable from
<your install dir>\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x86
to
<your install dir>\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64
(note the very last two characters)

path9263 | 2023-02-12 17:56