0 votes

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 (https://docs.godotengine.org/en/3.2/tutorials/plugins/gdnative/gdnative-c-example.html) 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::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.

asked Mar 21 in Engine by KoukouStudios (17 points)

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

1 Answer

0 votes

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.

answered Apr 20 by Paul Grad (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.