I have the following C++ build setup (using MSVC 2019 + Ninja):
build.bat
#echo off
mkdir build_folder
cd build_folder
call "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.21.27702/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.21.27702/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" ..
cd ..
CMakeLists.txt
cmake_minimum_required (VERSION 3.13)
project(TestScript CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} Script.cpp)
Script.cpp
int main()
{
return 0;
}
But when running build.bat I get this output:
-- The CXX compiler identification is MSVC 19.21.27702.2
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.21.27702/bin/HostX64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.21.27702/bin/HostX64/x64/cl.exe -- broken
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.14/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.21.27702/bin/HostX64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Coding/cmake_msvc_test/build_folder/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_6ecce
[1/2] Building CXX object CMakeFiles\cmTC_6ecce.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_6ecce.exe
FAILED: cmTC_6ecce.exe
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_6ecce.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MIB055~1\2019\PROFES~1\VC\Tools\MSVC\1421~1.277\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_6ecce.dir\testCXXCompiler.cxx.obj /out:cmTC_6ecce.exe /implib:cmTC_6ecce.lib /pdb:cmTC_6ecce.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
RC Pass 1: command "rc /foCMakeFiles\cmTC_6ecce.dir/manifest.res CMakeFiles\cmTC_6ecce.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specified
ninja: build stopped: subcommand failed.
I assume my cmake ninja call in build.bat is not quite correct (in terms of includes & compiler paths, etc). How would I need to tweak it?
Related
I was working on a C++ CMake project which was displaying and building fine in Visual Studio. Then I did something, I'm not sure what I did, but it seemed to break CMake. Now I get the following error:
Error CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: E:/DOCS/PROGRAMMING/22-02_Qt/vs_simple/VsConsole5/out/build/x64-debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_c94d5 && [1/2] Building C object CMakeFiles\cmTC_c94d5.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_c94d5.exe
FAILED: cmTC_c94d5.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_c94d5.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_c94d5.dir\testCCompiler.c.obj /out:cmTC_c94d5.exe /implib:cmTC_c94d5.lib /pdb:cmTC_c94d5.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_c94d5.dir\testCCompiler.c.obj /out:cmTC_c94d5.exe /implib:cmTC_c94d5.lib /pdb:cmTC_c94d5.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_c94d5.dir/intermediate.manifest CMakeFiles\cmTC_c94d5.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project. C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake 69
I get this error, even if I make a completely fresh CMake project via File > New > Project > CMake Project from within Visual Studio.
I've tried uninstalling and re-installing:
Visual Studio
Multiple different Windows SDK versions
CMake
I was hoping that doing this would return Visual Studio + CMake to a working state again but I am still getting the same error.
I also tried manually setting LIB and INCLUDE environment variables to the appropriate directories and that did get rid of the error but then the program wouldn't build, I got a bunch of errors like this:
Error (active) E1696 cannot open source file "ctype.h" VsSimple.exe - x64-Debug C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\cctype
I also tried deleting everything in the project folder apart from CMakeLists.txt, the .cpp file and the .h file. Unfortunately still no luck.
the name might be long but that's all I can think of to describe the issue. I was trying to follow a pybind11 tutorial and when I cloned all the examples my intellisense started acting up, first on VSCode with it not fiding the indlude folder (despite adding the path to the "C/C++ configuration") and then on Visual Studio 2022 with Cmake throwing an error when I tried to fix "C++ IntelliSense information may be out of date, generate the CMake cache to refresh".
The error is as follows :
`
Severity Code Description Project File Line Suppression State
Error CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/jackd/Desktop/exemple_pybind/out/build/x64-Debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_e044f && [1/2] Building C object CMakeFiles\cmTC_e044f.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_e044f.exe
FAILED: cmTC_e044f.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_e044f.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_e044f.dir\testCCompiler.c.obj /out:cmTC_e044f.exe /implib:cmTC_e044f.lib /pdb:cmTC_e044f.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
RC Pass 1: command "rc /fo CMakeFiles\cmTC_e044f.dir/manifest.res CMakeFiles\cmTC_e044f.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specified
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project. C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake 69
`
and since I'm no c++ pro I couldn't figure what this meant.
(I tried the other related topics: here and here)
There are plenty of questions and answers relating to this, but none of them have gotten me past my current problem. I can build using CMake/Ninja/clang-cl fine from within Visual Studio, but I want this to be done within a Github Action so I need to be able to do it from the command line - but it fails the configuration stage.
Running from Powershell:
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat' x64 10.0.22000.0
cmake -G "Ninja" `
-DVCPKG_TARGET_TRIPLET:STRING="x64-windows-static" `
-DCMAKE_CXX_COMPILER:FILEPATH="C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe" `
-DCMAKE_C_COMPILER:FILEPATH="C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe" `
-DCMAKE_RC_COMPILER:FILEPATH="C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/llvm-rc.exe" `
-DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" `
..\arg_router\
Yields:
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.1.0
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
... VCPKG stuff ...
-- Running vcpkg install - done
-- The CXX compiler identification is Clang 13.0.0 with MSVC-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/camde/Documents/workspace/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_81aba && [1/2] Building CXX object CMakeFiles\cmTC_81aba.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_81aba.exe
FAILED: cmTC_81aba.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_81aba.dir --rc=C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\llvm-rc.exe --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_81aba.dir\testCXXCompiler.cxx.obj /out:cmTC_81aba.exe /implib:cmTC_81aba.lib /pdb:cmTC_81aba.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D C:\Users\camde\Documents\workspace\build\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file C:/Users/camde/Documents/workspace/arg_router/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/camde/Documents/workspace/build/CMakeFiles/CMakeTmp/cmTC_81aba.exe -installedDir C:/Users/camde/Documents/workspace/arg_router/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_81aba.dir\testCXXCompiler.cxx.obj /out:cmTC_81aba.exe /implib:cmTC_81aba.lib /pdb:cmTC_81aba.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_81aba.dir/intermediate.manifest CMakeFiles\cmTC_81aba.dir/manifest.res" failed (exit code 1) with the following output:
lld-link: error: could not open 'kernel32.lib': no such file or directory
lld-link: error: could not open 'user32.lib': no such file or directory
lld-link: error: could not open 'gdi32.lib': no such file or directory
lld-link: error: could not open 'winspool.lib': no such file or directory
lld-link: error: could not open 'shell32.lib': no such file or directory
lld-link: error: could not open 'ole32.lib': no such file or directory
lld-link: error: could not open 'oleaut32.lib': no such file or directory
lld-link: error: could not open 'uuid.lib': no such file or directory
lld-link: error: could not open 'comdlg32.lib': no such file or directory
lld-link: error: could not open 'advapi32.lib': no such file or directory
lld-link: error: could not open 'msvcrtd.lib': no such file or directory
lld-link: error: could not open 'oldnames.lib': no such file or directory
ninja: build stopped: subcommand failed.
Those libraries are installed in C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64 which I would have thought vcvarsall.bat would have setup some env var that points to them - but clearly it didn't. What's weirder is that when I configure CMake from within VS, it doesn't need to pass the CMAKE_RC_COMPILER arg but if I don't then it fails stating that rc.exe can't be found.
Clearly VS is doing some extra configuration in the background before CMake is configured - what is it!?
As an extra data point, if I try to run the above CMake configuration command within the 'Developer Powershell for VS 2022', it fails for a different reason:
-- Running vcpkg install - done
-- The CXX compiler identification is Clang 13.0.0 with MSVC-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/camde/Documents/workspace/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_3b037 && [1/2] Building CXX object CMakeFiles\cmTC_3b037.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_3b037.exe
FAILED: cmTC_3b037.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_3b037.dir --rc=C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\llvm-rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x86\mt.exe --manifests -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_3b037.dir\testCXXCompiler.cxx.obj /out:cmTC_3b037.exe /implib:cmTC_3b037.lib /pdb:cmTC_3b037.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D C:\Users\camde\Documents\workspace\build\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file C:/Users/camde/Documents/workspace/arg_router/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/camde/Documents/workspace/build/CMakeFiles/CMakeTmp/cmTC_3b037.exe -installedDir C:/Users/camde/Documents/workspace/arg_router/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_3b037.dir\testCXXCompiler.cxx.obj /out:cmTC_3b037.exe /implib:cmTC_3b037.lib /pdb:cmTC_3b037.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_3b037.dir/intermediate.manifest CMakeFiles\cmTC_3b037.dir/manifest.res" failed (exit code 1) with the following output:
lld-link: error: <root>: undefined symbol: mainCRTStartup
ninja: build stopped: subcommand failed.
I'm trying to use CMake with Visual Studio for a 3D class, but whenever I open the provided CMake project, Visual Studio can't generate CMake files. I get the following error (some parts of the output were in French so I translated them):
CMake generation started with the default configuration: 'x64-Debug (par défaut)'.
1> Command line: "cmd.exe" /c ""c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\install\x64-Debug (par défaut)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented" 2>&1"
1> Working directory: D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\build\x64-Debug (par défaut)
1> [CMake] -- The C compiler identification is MSVC 19.26.28805.0
1> [CMake] -- The CXX compiler identification is MSVC 19.26.28805.0
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe - broken
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
1> [CMake] The C compiler
1> [CMake]
1> [CMake] "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe"
1> [CMake]
1> [CMake] is not able to compile a simple test program.
1> [CMake]
1> [CMake] It fails with the following output:
1> [CMake]
1> [CMake] Change Dir: D:/Scolaire/11 - 2A/INF443/1 - Tutoriels/create_window_commented/out/build/x64-Debug (par défaut)/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_cbae0 && [1/2] Building C object CMakeFiles\cmTC_cbae0.dir\testCCompiler.c.obj
1> [CMake] [2/2] Linking C executable cmTC_cbae0.exe
1> [CMake] FAILED: cmTC_cbae0.exe
1> [CMake] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_cbae0.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_cbae0.dir\testCCompiler.c.obj /out:cmTC_cbae0.exe /implib:cmTC_cbae0.lib /pdb:cmTC_cbae0.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
1> [CMake] RC Pass 1: command "rc /fo CMakeFiles\cmTC_cbae0.dir/manifest.res CMakeFiles\cmTC_cbae0.dir/manifest.rc" failed (exit code 0) with the following output:
1> [CMake] The specified file could not be found
1> [CMake] ninja: build stopped: subcommand failed.
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake] CMake will not be able to correctly generate this project.
1> [CMake] Call Stack (most recent call first):
1> [CMake] CMakeLists.txt:3 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "D:/Scolaire/11 - 2A/INF443/1 - Tutoriels/create_window_commented/out/build/x64-Debug (par défaut)/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "D:/Scolaire/11 - 2A/INF443/1 - Tutoriels/create_window_commented/out/build/x64-Debug (par défaut)/CMakeFiles/CMakeError.log".
1> Execution failed 'cmd.exe' '/c ""c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\install\x64-Debug (par défaut)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented" 2>&1"'. Error: ''cmd.exe' '/c ""c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\install\x64-Debug (par défaut)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented" 2>&1"' was returned with end code: 1'.
Other people in my class are using the same provided files and don't have errors so the problem can't be from this. I use Windows 10 and the latest version of Visual Studio (I tried to uninstall and reinstall it). The C++ and CMake tools are installed within Visual Studio.
The provided project should only open an empty windows, it looks like this:
PS D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented> ls
Répertoire : D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 25/05/2020 14:09 .vs
d----- 25/05/2020 14:09 out
d----- 03/08/2018 15:10 src
-a---- 11/03/2020 08:59 175 CMakeLists.txt
-a---- 02/03/2020 17:37 214 Makefile
-a---- 02/03/2020 17:37 229 meson.build
-a---- 11/03/2020 08:59 847 README
Do you know what the cause could be ? Thanks!
The problem was from the CMakeLists.txt, the parameters inside this file were for Unix instead of Windows.
Edit: the CMakeLists.txt that didn't work was this:
cmake_minimum_required(VERSION 2.8)
project(pgm)
set(CMAKE_CXX_FLAGS "-O2 -g -std=c++11 -Wall -Wextra")
add_executable(pgm src/main.cpp)
target_link_libraries(pgm glfw)
I made the following changes.
From set(CMAKE_CXX_FLAGS "-O2 -g -std=c++11 -Wall -Wextra") to:
set(CMAKE_BUILD_TYPE Debug)
set(GLFW_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib_windows/glfw3_win/include")
include_directories(${GLFW_INCLUDE_DIRS})
set(GLFW_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib_windows/glfw3_win/lib/glfw3.lib") # Set directory to precompiled version of glfw3
From target_link_libraries(pgm glfw) to:
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${source_files}) # Allow to explore source directories as a tree
target_link_libraries(pgm ${GLFW_LIBRARIES})
I didn't write this code, I just understood that the wrong lines of code were meant for Unix so I replaced them with the right lines of code from another CMakeLists.txt from a similar provided OpenGL project.
My solution — add this right before 'project' in top cmake file:
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
I'm using the latest VS 2019 16.2, which is supposed to have Clang with MSBuild support as well Clang w/ CMake of course.
I installed the CMake components as well as the Clang-cl for v142 build tools (But not the Clang Compiler component that comes with VS!) because I already have Clang compiler v8.0.0 installed in the default path in my system.
I want to use Clang (either through MSBuild or CMake) but both approaches failed.
VS simply doesn't seem to detect my compiler (although the version is supported, supposedly).
Is there a way I can manually make it detect it? May add a path in some options or reinstall clang?
I don't want to install the VS one for my specific reasons.
Severity Code Description Project File Line Suppression State
Error CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"c:/program files (x86)/microsoft visual studio/2019/community/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/HP/Source/Repos/CMakeProject1/out/build/x64-Clang-Debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_8f083
[1/2] Building C object CMakeFiles\cmTC_8f083.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_8f083.exe
FAILED: cmTC_8f083.exe
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_8f083.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1422~1.279\bin\Hostx86\x86\link.exe /nologo CMakeFiles\cmTC_8f083.dir\testCCompiler.c.obj /out:cmTC_8f083.exe /implib:cmTC_8f083.lib /pdb:cmTC_8f083.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
RC Pass 1: command "rc /foCMakeFiles\cmTC_8f083.dir/manifest.res CMakeFiles\cmTC_8f083.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specified
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project. C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake 60