早前把VS2015卸了,安裝了VS2017。由於VS2017安裝的時候能夠選擇安裝VS2015編譯套件,也就安裝了。使用上一直沒有什麼問題,因此也沒有注意到這個細節。
後來使用cmake生成項目工程文件的時候,選擇VS2015編譯器,卻提示找不到C編譯器。shell
CMake Error at CMakeLists.txt:3 (project): No CMAKE_CXX_COMPILER could be found.
本來覺得是環境變量沒有設置好,查看了一下VS140COMNTOOLS
的路徑是對的。
而後試着在VS2015本機工具命令提示符
工具下試試cmake
行不行。結果一打開VS2015本機工具命令提示符就提示讓你安裝Visual Studio or C++ Build SKU
express
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
這個文件,發現了問題所在(見下面代碼註釋)。windows
@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
文件,也沒有什麼收穫。
可是能夠經過直接指定編譯器來使用,這是能夠的。app
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
工具