Compile GDExtension in Visual Studio 2022

Godot Version

4.4

Question

Hi, I’m trying to setup visual studio 2022 to compile gdextensions. I’ve cloned godot-cpp (4.4) and compiled it with scons using “scons platform=windows”.
It created lib: libgodot-cpp.windows.template_debug.x86_64.lib
When I try to compile my project (64x debug) with this lib I get:
(error_macros.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’ in gdexample.obj
(error_macros.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MTd_StaticDebug’ in gdexample.obj
(memory.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’ in gdexample.obj
(memory.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MTd_StaticDebug’ in gdexample.obj
(string.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’ in gdexample.obj
(string.windows.template_debug.x86_64.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MTd_StaticDebug’ in gdexample.obj

The runtime flags must match for all objects linked together, so your project is using something different to godot-cpp

so however your setting up your project you need to make sure its the same.

from the error, it looks like you are trying to link your projetc as MT_StaticDebug to godot-cpp which was built with MT_StaticRelease?

I’d review your build scripts.

I used default scons script to build godot-cpp libarary
and used command:

scons platform=windows custom_api_file=…/…/extension_api.json

I also tried to add target=template_debug
But in vs logs it still MT_StaticRelease
Yes, it works if I swithc vs project to release config and set runtime lib to /MT
But to me looks odd, to be honest I’m not c++ expert
Using same lib with script from godot docs tutorial using scons script works fine, it builds extension library that I can then use in godot

Ok, after spending some time studying scons script I figured out that I need to launch it with parameter

debug_crt=yes

1 Like