godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.68k stars 20.11k forks source link

Running into unresolved external symbol errors during GDNative example #62128

Open kburchfiel opened 2 years ago

kburchfiel commented 2 years ago

Godot version

3.4

System information

Windows 10

Issue description

I am going through the GDNative C++ example and am currently on the 'Compiling the plugin' step. I'm using Visual Studio 2022 and versions 3.4 of godot-headers and godot-cpp.

When I try to compile the sample plugin with scons platform=windows, I receive the following set of error messages:

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<float>::_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<float>::_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<class godot::GDExample>(void)" (??$register_class@VGDExample@godot@@@godot@@YAXXZ)
gdlibrary.obj : error LNK2001: unresolved external symbol _nativescript_1_1_api
gdlibrary.obj : error LNK2001: unresolved external symbol "private: static void * godot::Sprite::_detail_class_tag" (?_detail_class_tag@Sprite@godot@@0PAXA)
godot-cpp\bin\libgodot-cpp.windows.debug.64.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
demo\bin\win64\libgdexample.dll : fatal error LNK1120: 13 unresolved externals
scons: *** [demo\bin\win64\libgdexample.dll] Error 1120
scons: building terminated because of errors.

I'm not sure whether I need to update the Sconstruct file, the gdexample.cpp/gdexample.h/gdlibrary.cpp files, or something else. Thank you in advance for your help!

Steps to reproduce

I believe I've followed the steps in the GDNative C++ tutorial accurately so far. Perhaps my use of Visual Studio 2022 (as opposed to an earlier version) is contributing to this issue.

Minimal reproduction project

The .zip version of my folder was too large to upload here, so I uploaded a copy to Google Drive instead:

https://drive.google.com/file/d/1wFYuPgbiIuqVddUoefdQJFFJVMYlu03W/view?usp=sharing

3ddelano commented 2 years ago

@Chaosus wrong topic added, its v.3.4 so gdnative instead of gdextension

3ddelano commented 2 years ago

@kburchfiel It compiles fine for me on VS2019. Seems to be an issue with VS2022.

In godot-cpp I ran: scons target=release platform=windows generate_bindings=yes In root folder I ran: scons target=release platform=windows

image

3ddelano commented 2 years ago

An important note here in the error you posted "library machine type 'x64' conflicts with target machine type 'x86'" says that your machine needs to be x64 bits. Perhaps that maybe the issue.

Chaosus commented 2 years ago

wrong topic added, its v.3.4 so gdnative instead of gdextension

There is no gdnative label anymore, and gdextension is replacement

hansemro commented 2 years ago

SConstruct from GDNative example does not support 32-bits. Visual Studio 2022 should be fine (at least on my end).

kburchfiel commented 2 years ago

Thanks for the quick responses. I do have a 64-bit machine, so I'm wondering what might be causing it to try to compile within 32 bits. I think I added bits=64 as a parameter but still retrieved an error (but I can retry this). Is there another way to force 64-bit compilation?

Also, I had already run scons target=release platform=windows generate_bindings=yes within godot-cpp before uploading the folder. Is it necessary to rerun this before running scons in the root folder?

3ddelano commented 2 years ago

One way to get the x64 bits is to run the commands in a x64 Native Tools command prompt from Visual Studio. There should be shortcuts created when you installed Visual Studio.

kburchfiel commented 2 years ago

@3ddelano That solved it, thank you! I was able to compile the plugin successfully by using x64 Native Tools Command Prompt for VS 2022 instead of Developer Command Prompt for VS 2022.