visual studio 编译cmake项目

当编译出现问题

message(FATAL_ERROR "The C compiler\n  \"${CMAKE_C_COMPILER}\"\n"
      "is not able to compile a simple test program.\nIt fails "
      "with the following output:\n  ${_output}\n\n"
      "CMake will not be able to correctly generate this project.")

控制台提示如下:

1> 已为默认配置“x64-Debug”启动 CMake 生成。
1> 发现和使用 vcpkg 工具链文件(C:/Users/dell/Downloads/vcpkg-master/vcpkg-master/scripts/buildsystems/vcpkg.cmake)。
1> 命令行: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="D:\源码\测试代码\CMakeProject7\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" -DCMAKE_TOOLCHAIN_FILE="C:/Users/dell/Downloads/vcpkg-master/vcpkg-master/scripts/buildsystems/vcpkg.cmake" "D:\源码\测试代码\CMakeProject7" 2>&1"
1> 工作目录: D:\源码\测试代码\CMakeProject7\out\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.29.30133.0
1> [CMake] -- The CXX compiler identification is MSVC 19.29.30133.0
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - failed
1> [CMake] -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
1> [CMake] -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - broken
1> [CMake] CMake Error at D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
1> [CMake]   The C compiler
1> [CMake] 
1> [CMake]     "D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/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:/源码/测试代码/CMakeProject7/out/build/x64-Debug/CMakeFiles/CMakeTmp
1> [CMake]     
1> [CMake]     Run Build Command(s):D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_25e16 && [1/2] Building C object CMakeFiles\cmTC_25e16.dir\testCCompiler.c.obj
1> [CMake]     [2/2] Linking C executable cmTC_25e16.exe
1> [CMake]     FAILED: cmTC_25e16.exe 
1> [CMake]     cmd.exe /C "cd . && "D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_25e16.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- "D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_25e16.dir\testCCompiler.c.obj  /out:cmTC_25e16.exe /implib:cmTC_25e16.lib /pdb:cmTC_25e16.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 D:\Դ��\���Դ���\CMakeProject7\out\build\x64-Debug\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file C:/Users/dell/Downloads/vcpkg-master/vcpkg-master/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary D:/Դ��/���Դ���/CMakeProject7/out/build/x64-Debug/CMakeFiles/CMakeTmp/cmTC_25e16.exe -installedDir C:/Users/dell/Downloads/vcpkg-master/vcpkg-master/installed/x64-windows/debug/bin -OutVariable out""
1> [CMake]     Access is denied.
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:6 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "D:/源码/测试代码/CMakeProject7/out/build/x64-Debug/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "D:/源码/测试代码/CMakeProject7/out/build/x64-Debug/CMakeFiles/CMakeError.log".
1> “C:\WINDOWS\system32\cmd.exe”“/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="D:\源码\测试代码\CMakeProject7\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" -DCMAKE_TOOLCHAIN_FILE="C:/Users/dell/Downloads/vcpkg-master/vcpkg-master/scripts/buildsystems/vcpkg.cmake" "D:\源码\测试代码\CMakeProject7" 2>&1"”执行失败,出现错误:““C:\WINDOWS\system32\cmd.exe”“/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="D:\源码\测试代码\CMakeProject7\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" -DCMAKE_TOOLCHAIN_FILE="C:/Users/dell/Downloads/vcpkg-master/vcpkg-master/scripts/buildsystems/vcpkg.cmake" "D:\源码\测试代码\CMakeProject7" 2>&1"”已返回,并带有退出代码: 1”。

解决方案:

在cmakelists.txt文件中,在project前面添加即可

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
 

你可能感兴趣的:(cmake,visual,studio,ide)