asmaloney / GDExtensionTemplate

📜 A template project for building Godot 4 GDExtensions using CMake
The Unlicense
228 stars 22 forks source link

LNK2038 errors when compiling under Windows 11 #43

Closed oparisy closed 1 year ago

oparisy commented 1 year ago

I gave a try at compiling GDExtensionTemplate unmodified:

$ git clone https://github.com/asmaloney/GDExtensionTemplate.git
$ cd GDExtensionTemplate
$ git submodule update --init --recursive
$ cd ..
$ cmake -B GDExtensionTemplate-build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=GDExtensionTemplate-install GDExtensionTemplate
$ cmake --build GDExtensionTemplate-build --parallel

At that step I get errors of the form (multiple such lines, 2 per .obj):

godot-cpp.windows.release.64.lib(canvas_item.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Example.obj [C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate.vcxproj]
godot-cpp.windows.release.64.lib(canvas_item.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in Example.obj [C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate.vcxproj]
godot-cpp.windows.release.64.lib(error_macros.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Example.obj [C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate.vcxproj]
godot-cpp.windows.release.64.lib(error_macros.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in Example.obj [C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate.vcxproj]

Concluded with:

     Creating library C:/Dev/GDExtension/GDExtensionTemplate-build/Debug/GDExtensionTemplate-d.lib and object C:/Dev/GDExtension/GDExtensionTemplate-build/Debug/GDExtensionTemplate-d.exp
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library [C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate.vcxproj]
C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate\lib\Windows-AMD64\Debug\GDExtensionTemplate-d.dll : fatal error LNK1319: 84 mismatches detected [C:\Dev\GDExtension\GDExtensionTemplate-build\GDExtensionTemplate.vcxproj]

My setup: Windows 11, CMake 3.25.2, Visual Studio Community 2022, Python 3.11.1. I did not install Ccache since Windows support seems spotty.

oparisy commented 1 year ago

There is a discussion of very similar errors on https://github.com/godotengine/godot/issues/26046

asmaloney commented 1 year ago

Hmmm... I wonder if this is a "build type" vs. "multiconfig" issue.

For the CMake steps, could you please try:

$ cmake -B GDExtensionTemplate-build -G"Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=GDExtensionTemplate-install GDExtensionTemplate
$ cmake --build GDExtensionTemplate-build --config Release
oparisy commented 1 year ago

Sure! The first CMake step leads to the following error:

C:\Dev>cmake -B GDExtensionTemplate-build -G"Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=GDExtensionTemplate-install GDExtensionTemplate
-- Using CMake 3.25.2
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The CXX compiler identification is MSVC 19.34.31937.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building GDExtensionTemplate for AMD64 on Windows
-- [GDExtensionTemplate] Treating warnings as errors
-- Using git: C:/Program Files/Git/cmd/git.exe (git version 2.39.1.windows.1)
-- GDExtensionTemplate version: godot-4.0-beta-17
-- Install directory: C:/Dev/GDExtensionTemplate-install/GDExtensionTemplate/
CMake Error at templates/CMakeLists.txt:15 (message):
  CMAKE_BUILD_TYPE must be set to Debug or Release

-- Configuring incomplete, errors occurred!
See also "C:/Dev/GDExtensionTemplate-build/CMakeFiles/CMakeOutput.log".
asmaloney commented 1 year ago

😆 I put in that check because of this problem. Basically godot-cpp sets a bunch of options explicitly (👹) so we have no control over things and must try to match what it's doing rather than the other way around.

Next attempt:

cmake -B GDExtensionTemplate-build -G"Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=GDExtensionTemplate-install GDExtensionTemplate
cmake --build GDExtensionTemplate-build
oparisy commented 1 year ago

Oh I was trying just that (adding the extra -DCMAKE_BUILD_TYPE=Release) and yes, this time it works:

$ cmake -B GDExtensionTemplate-build -G"Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=GDExtensionTemplate-install -DCMAKE_BUILD_TYPE=Release GDExtensionTemplate
$ cmake --build GDExtensionTemplate-build --config Release

Leads to:

(...)
  Compiling...
  utility_functions.cpp
  object.cpp
  object.cpp
  godot-cpp.vcxproj -> C:\Dev\GDExtensionTemplate-build\extern\godot-cpp\bin\Release\godot-cpp.windows.release.64.lib
  Building Custom Rule C:/Dev/GDExtensionTemplate/CMakeLists.txt
  Example.cpp
  GDExtensionTemplate.cpp
  RegisterExtension.cpp
     Creating library C:/Dev/GDExtensionTemplate-build/Release/GDExtensionTemplate.lib and object C:/Dev/GDExtensionTemplate-build/Releas
  e/GDExtensionTemplate.exp
  Generating code
  Previous IPDB not found, fall back to full compilation.
  All 2381 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
  Finished generating code
  GDExtensionTemplate.vcxproj -> C:\Dev\GDExtensionTemplate-build\GDExtensionTemplate\lib\Windows-AMD64\Release\GDExtensionTemplate.dll
  Building Custom Rule C:/Dev/GDExtensionTemplate/CMakeLists.txt
asmaloney commented 1 year ago

👍 Thank you for the report and the testing.

I'll update the README.