新装VS2017,CMake 新建工程报错:cl.exe is not able to compile a simple test program.

问题描述:

有两位同事先后使用 VS2017 下载包安装到新电脑,安装盘选的非系统盘。安装完后,均出现普通工程可正常编译运行,CMake 工程无法编译的错误,其中第一位同事报错:

1> -- The C compiler identification is MSVC 19.16.27042.0
1> -- The CXX compiler identification is MSVC 19.16.27042.0
1> -- Check for working C compiler: E:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe
1> -- Check for working C compiler: E:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe -- broken
1> -- Configuring incomplete, errors occurred!
...


1> CMake Error at E:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
1>   The C compiler
1> 
1>     "E:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe"
1> 
1>   is not able to compile a simple test program.
1> 
...
1>     
1>     Run Build Command:"E:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" "cmTC_4ed4b"
1>     [1/2] Building C object CMakeFiles\cmTC_4ed4b.dir\testCCompiler.c.obj
1>     [2/2] Linking C executable cmTC_4ed4b.exe
1>     FAILED: cmTC_4ed4b.exe 
1>     cmd.exe /C "cd . && "E:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_4ed4b.dir --manifests  -- "E:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_4ed4b.dir\testCCompiler.c.obj  /out:cmTC_4ed4b.exe /implib:cmTC_4ed4b.lib /pdb:cmTC_4ed4b.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>     RC Pass 1: command "rc /foCMakeFiles\cmTC_4ed4b.dir/manifest.res CMakeFiles\cmTC_4ed4b.dir/manifest.rc" failed (exit code 0) with the following output:
1>     系统找不到指定的文件。
1>     ninja: build stopped: subcommand failed.
1>     
1> 
1>   
1> 
1>   CMake will not be able to correctly generate this project.
1> Call Stack (most recent call first):
1>   D:\CMakeProject1\CMakeLists.txt(6): (project)

重点在于倒数第7~4行:

RC Pass 1: command "rc /foCMakeFiles\cmTC_4ed4b.dir/manifest.res CMakeFiles\cmTC_4ed4b.dir/manifest.rc" failed (exit code 0) with the following output:
1>     系统找不到指定的文件。 

第二位同事报错:

1> -- The C compiler identification is MSVC 19.16.27042.0
1> -- The CXX compiler identification is MSVC 19.16.27042.0
1> -- Check for working C compiler: D:/sofeware/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe
1> -- Check for working C compiler: D:/sofeware/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe -- broken
1>   The C compiler
1> 
1>     "D:/sofeware/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe"
1> 
1>   is not able to compile a simple test program.
1> 
...
1>     
1>     Run Build Command:"D:\SOFEWARE\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "cmTC_fb744"
1>     [1/2] Building C object CMakeFiles\cmTC_fb744.dir\testCCompiler.c.obj
1>     [2/2] Linking C executable cmTC_fb744.exe
1>     FAILED: cmTC_fb744.exe 
1>     cmd.exe /C "cd . && D:\sofeware\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_fb744.dir --manifests  -- D:\sofeware\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_fb744.dir\testCCompiler.c.obj  /out:cmTC_fb744.exe /implib:cmTC_fb744.lib /pdb:cmTC_fb744.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>     LINK Pass 1: command "D:\sofeware\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_fb744.dir\testCCompiler.c.obj /out:cmTC_fb744.exe /implib:cmTC_fb744.lib /pdb:cmTC_fb744.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_fb744.dir/intermediate.manifest CMakeFiles\cmTC_fb744.dir/manifest.res" failed (exit code 1104) with the following output:
1>     LINK : fatal error LNK1104: 无法打开文件“kernel32.lib”
1>     ninja: build stopped: subcommand failed.
1>     
1> 
1>   
1> 
1>   CMake will not be able to correctly generate this project.


LINK : fatal error LNK1104: 无法打开文件“kernel32.lib”

第二位同事报错信息更加明确,是找不到“kernel32.lib”,也就是需要引用的系统库路径等没有配置。

 

解决方法:

添加了如下环境变量:

https://i-blog.csdnimg.cn/blog_migrate/c1e9628c7e408c4c800e0c30ddb82332.png

 

 

其中%KITS_HOME%为 Windows Kits 的路径,图中定义为了 D:\Windows Kits\10

最后一个 %VS2017_HOME%\Common7\IDE 可能不需要。

 

问题原因推测:

可能是安装的时候,CMake 没有自动配置相关的头文件路径和库路径;不知道是不是没有采用默认安装到系统盘的原因,或者使用 iso 安装的话是否也会出现这样的问题。

非 CMake 的 VS 工程可正常编译运行,是因为其工程配置中有默认的头文件路径和库路径变量.

之前自己也是用相同的下载包安装的 VS2017 ,没有额外手动配置,安装完就能正常使用 CMake,但是在那之前通过 iso 安装过 VS2012,感觉应该没关系。。不好猜测具体是什么原因。

 

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值