Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LNK2038 errors when compiling under Windows 11 #43

Closed
oparisy opened this issue Feb 4, 2023 · 6 comments
Closed

LNK2038 errors when compiling under Windows 11 #43

oparisy opened this issue Feb 4, 2023 · 6 comments

Comments

@oparisy
Copy link

oparisy commented Feb 4, 2023

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
Copy link
Author

oparisy commented Feb 4, 2023

There is a discussion of very similar errors on godotengine/godot#26046

@asmaloney
Copy link
Owner

asmaloney commented Feb 4, 2023

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
Copy link
Author

oparisy commented Feb 4, 2023

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
Copy link
Owner

😆 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
Copy link
Author

oparisy commented Feb 4, 2023

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
Copy link
Owner

👍 Thank you for the report and the testing.

I'll update the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants