godotengine / godotengine/godot-cpp
[WIN/CLANG/CMAKE] Incorrect linker flags when configuring on the Windows.
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
no matter
### godot-cpp version
godot-4.5-stable
### System information
Windows 11
### Issue description
Incorrect linker flags are used when building the project in the Windows + Clang (GNU-like CLI) + Ninja + CMake environment
```
FAILED: [code=1] reproduce.dll reproduce.lib
C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -nostartfiles -nostdlib -O0 -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -g -Xclang -gcodeview -shared -Wl,--no-undefined -lstdc++ -fuse-ld=lld-link -o reproduce.dll -Xlinker /MANIFEST:EMBED -Xlinker /implib:reproduce.lib -Xlinker /pdb:reproduce.pdb -Xlinker /version:0.0 CMakeFiles/reproduce.dir/empty.cpp.obj bin/libgodot-cpp.windows.template_debug.x86_64.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: warning: ignoring unknown argument '--no-undefined'
lld-link: error: could not open 'stdc++.lib': no such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
```
Incorrect linker flags are added [here](https://github.com/godotengine/godot-cpp/blob/e83fd0904c13356ed1d4c3d09f8bb9132bdc6b77/cmake/windows.cmake#L99). I assume this was written with the expectation that we are using MinGW/MSYS with a POSIX runtime, but that’s not the case here.
t would be nice to have an option to prevent targets that use godot-cpp from being polluted with its PUBLIC linker flags, and instead allow the higher-level project (the one that calls add_subdirectory(godot-cpp)) to control them.
### Steps to reproduce
1. Download [reproduce.zip](https://github.com/user-attachments/files/22772315/reproduce.zip)
2. Configure (options below)
3. Try to build
4. Wait for the linking stage
Configure options:
-G Ninja
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_MAKE_PROGRAM=ninja
-DCMAKE_C_COMPILER=C:/Program Files/LLVM/bin/clang.exe _**(It’s possible to use Clang installed via Chocolatey)**_
-DCMAKE_CXX_COMPILER=C:/Program Files/LLVM/bin/clang++.exe
### Minimal reproduction project
[reproduce.zip](https://github.com/user-attachments/files/22772315/reproduce.zip)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.