1、起因

早前把VS2015卸了,安装了VS2017。因为VS2017安装的时候可以选择安装VS2015编译套件,也就安装了。使用上一直没有什么问题,所以也没有注意到这个细节。

后来使用cmake生成项目工程文件的时候,选择VS2015编译器,却提示找不到C编译器。

CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.

2、解决

原本以为是环境变量没有设置好,查看了一下VS140COMNTOOLS的路径是对的。

然后试着在VS2015本机工具命令提示符工具下试试cmake行不行。结果一打开VS2015本机工具命令提示符就提示让你安装Visual Studio or C++ Build SKU

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>vcvarsall.bat "x86" "8.1"
Error in script usage. The correct usage is:
vcvarsall.bat [option]
or
vcvarsall.bat [option] store
or
vcvarsall.bat [option] [version number]
or
vcvarsall.bat [option] store [version number]
where [option] is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
where [version number] is either the full Windows 10 SDK version number or "8.1" to use the windows 8.1 SDK
:
The store parameter sets environment variables to support
store (rather than desktop) development.
:
For example:
vcvarsall.bat x86_amd64
vcvarsall.bat x86_arm store
vcvarsall.bat x86_amd64 10.0.10240.0
vcvarsall.bat x86_arm store 10.0.10240.0
vcvarsall.bat x64 8.1
vcvarsall.bat x64 store 8.1
:
Please make sure either Visual Studio or C++ Build SKU is installed.

问题看来就在这里,仔细查看了一下C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat这个文件,发现了问题所在(见下面代码注释)。

@echo off

REM VC command prompt depends on env. variable installed during VS. This causes VC command prompt to break for C++ Build SKU.
REM So if VS is not installed and C++ Build SKU is installed, set appropriate environment for C++ Build SKU by calling into it's batch file.
REM C++ Build SKU supports only desktop development environment. :: 上面是注释不用管,问题就出现在下面的两行
:: 下面这一行检查devenv.exe这个文件,但是这里是没有的
if exist "%~dp0..\common7\IDE\devenv.exe" goto setup_VS
:: 检查到没有devenv.exe,也没有wdexpress.exe文件,就跳过去检查vs build tools了
if not exist "%~dp0..\common7\IDE\wdexpress.exe" goto setup_buildsku :setup_VS
if "%1" == "" goto x86
if "%2" == "" goto check_platform
echo "1 is %1 2 is %2"
setlocal
set _Argument2=%2
if not "%2"=="store" if not "%2"=="8.1" if not "%_Argument2:~0,3%"=="10." goto usage
endlocal .... 此处省略很多行 :setup_buildsku
if not exist "%~dp0..\..\Microsoft Visual C++ Build Tools\vcbuildtools.bat" goto usage
set CurrentDir=%CD%
call "%~dp0..\..\Microsoft Visual C++ Build Tools\vcbuildtools.bat" %1 %2
cd /d %CurrentDir%
goto :eof

这里解决的办法很简单,把多余的两行检查注释掉就行了。(可以拷贝了一份vcvarsall.bat,在副本里面进行修改)

但是这样做只是在命令行下可以用了,cmake还是No CMAKE_CXX_COMPILER,检测不到编译器。

查看了一下CMAKE安装目录下的share\cmake-3.7\Modules\Compiler\MSVC-CXX.cmake文件,也没有什么收获。

但是可以通过直接指定编译器来使用,这是可以的。

cmake -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe" .

在VS2017的安装目录下还有一份VS2015的编译环境。默认路径是C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\bin

最新文章

  1. Cesium原理篇:3最长的一帧之地形(4:重采样)
  2. 你还记得windows workflow foundation吗
  3. BOM&Navigator对象
  4. Jquery 等待ajax返回数据loading控件ShowLoading组件
  5. [xUI] ligerUI开发框架简介和搭建
  6. asp.net MVC EF Where 过滤条件怎么写
  7. Android 官方新手指导教程
  8. httl开源JAVA模板引擎,动态HTML页面输出
  9. UML用例图总结(转)
  10. 错误记录-spring+mybatis
  11. 四、I/O
  12. C#程序员应该养成的程序性能优化写法
  13. <转>jmeter(十八)关联之XPath Extractor
  14. 常见的原生javascript DOM操作
  15. java基础知识-新手上路注意事项一
  16. WebService连接postgresql( 失败尝试)
  17. LeetCode题解之Add two numbers
  18. KMP算法模板&&扩展
  19. Kali-linux使用Maltego收集信息
  20. HDU2189 来生一起走

热门文章

  1. 启明星Helpdesk与微信配置说明
  2. MAT(Memory Analyzer Tool)内存分析工具的使用
  3. Guava之ImmutableMap使用示例
  4. [填坑]解决"Your MaintenanceTool appears to be older than 3.0.2. ."问题
  5. 检查安装的 DirectX 版本
  6. sql server 由于登入失败而无法启动服务
  7. Validate Binary Search Tree leetcode java
  8. JavaScript中textRange对象使用方法总结
  9. [总结]Jquery api 快速参考
  10. Spark Strcutured Streaming中使用Dataset的groupBy agg 与 join 示例(java api)