<root>: undefined symbol: mainCRTStartup on native Clang build on Windows
I was trying to port a legacy CMakeLists.txt to work on Windows with native Clang (Clang with GNU style command-line) and Ninja
However, there seem to be certain constellations with which cmake is... rather unhappy
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
project(addon)
doesn't work
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
project(addon)
works
cmake_minimum_required(VERSION 3.13)
project(addon)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
works
works = compiler is recognised and cmake -DCMAKE_BUILD_TYPE="RELEASE" ..
succeeds
Error log if it doesn't work:
PS C:\devspace\node-corelib\build> cmake -DCMAKE_BUILD_TYPE="RELEASE" -GNinja ..
-- The C compiler identification is Clang 12.0.1 with GNU-like command-line
-- The CXX compiler identification is Clang 12.0.1 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/devspace/node-corelib/build
PS C:\devspace\node-corelib\build> cmake -DCMAKE_BUILD_TYPE="RELEASE" -GNinja ..
-- The C compiler identification is Clang 12.0.1 with GNU-like command-line
-- The CXX compiler identification is Clang 12.0.1 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"C:/Program Files/LLVM/bin/clang++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/devspace/node-corelib/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/PROGRA~1/ninja/ninja.exe cmTC_3cf9f && [1/2] Building CXX object CMakeFiles/cmTC_3cf9f.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_3cf9f.exe
FAILED: cmTC_3cf9f.exe
cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Xlinker /subsystem:console CMakeFiles/cmTC_3cf9f.dir/testCXXCompiler.cxx.obj -o cmTC_3cf9f.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_3cf9f.lib -Xlinker /pdb:cmTC_3cf9f.pdb -Xlinker /version:0.0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: error: <root>: undefined symbol: mainCRTStartup
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "C:/devspace/node-corelib/build/CMakeFiles/CMakeOutput.log".
See also "C:/devspace/node-corelib/build/CMakeFiles/CMakeError.log".
Cmake cmake version 3.22.0-rc2