2017-04-14 93 views
3

編輯: 已將此發佈到他們的問題跟蹤器,並與一些CMake開發人員一起通過它,這實際上不是CMake問題。我的MSBuild安裝導致它返回「操作成功完成」。錯誤。總體上仍然沒有解決這個問題,但是這縮小了潛在的原因。我想在Windows上使用MS Visual C++構建工具2015(注意:不是完整的Visual Studio)構建一個CMake項目。 CMake的,但是,顯然無法找到cl.exe時CMake與Microsoft Visual C++構建工具

cmake .. 
-- Building for: Visual Studio 14 2015 
-- The C compiler identification is unknown 
-- The CXX compiler identification is unknown 
CMake Error at CMakeLists.txt:4 (project): 
    No CMAKE_C_COMPILER could be found. 



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

我懷疑這是因爲CMake的是希望找到編譯器與Visual Studio安裝,但也許是獨立的構建工具安裝在不同的位置?是否可以配置CMake在其他地方尋找編譯器?

編輯:爲了把這個可能性關掉,cl.exe肯定是安裝的。當我打開Visual C++殼(添加工具路徑)輸出的cl.exe:

cl.exe 
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86 
Copyright (C) Microsoft Corporation. All rights reserved. 

usage: cl [ option... ] filename... [ /link linkoption... ] 

這是我從這麼運行的cl.exe的cmake ..同樣的環境,絕對是對的路徑探索由CMake。

編輯2:綜觀CMakeError.log文件我看到下面的

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. 
Compiler: 
Build flags: 
Id flags: 

The output was: 
1 
Microsoft (R) Build Engine version 14.0.25420.1 
Copyright (C) Microsoft Corporation. All rights reserved. 

Build started 4/14/2017 11:58:13 AM. 
Project "E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets). 
PrepareForBuild: 
    Creating directory "Debug\". 
    Creating directory "Debug\CompilerIdCXX.tlog\". 
InitializeBuildStatus: 
    Creating "Debug\CompilerIdCXX.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified. 
ClCompile: 
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:queue CMakeCXXCompilerId.cpp 
TRACKER : error TRK0002: Failed to execute command: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" @C:\Users\<user>\AppData\Local\Temp\tmpa0925a9f05d5426d82afdcee8d722031.rsp". The operation completed successfully. [E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj] 


Done Building Project "E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED. 

Build FAILED. 

"E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) -> 
(ClCompile target) -> 
    TRACKER : error TRK0002: Failed to execute command: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" @C:\Users\<user>\AppData\Local\Temp\tmpa0925a9f05d5426d82afdcee8d722031.rsp". The operation completed successfully. [E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj] 

    0 Warning(s) 
    1 Error(s) 

Time Elapsed 00:00:01.21 

這看起來像是某種輸出兼容性問題的幾個變種,尤其是「錯誤:操作成功完成。」線。我使用CMake 3.8.0-rc4和Visual C++ 2015構建工具。有任何想法嗎?

編輯3: 我認爲從3.8.0-rc4升級到3.8.0可能會解決它,但無濟於事。我還認爲我正在使用64位CMake試圖構建一個32位程序,所以我改變了這一點。沒有運氣。

編輯4: 另外,爲了記錄,這確實與裝有完整VS 2015的PC上的CMake一起構建。

+0

是的。而且我再次檢查了我可以在該shell中手動調用cl.exe。 –

+0

這就是我從中獲得上述輸出的地方,甚至是相同的終端實例。 –

+0

這看起來像一個CMake錯誤。嘗試用盡可能多的信息來報告錯誤[這裏](https://gitlab.kitware.com/cmake/cmake/issues)。也很好地爲你的問題添加儘可能多的信息! – tambre

回答

0

我不確定我是否爲The operation completed successfully問題提供了一個解決方案,但是我能夠使用cmake 3.8.1和C++ 2015 BuildTools編譯一個[big]真實項目。

訣竅是簡單地使用「VS2015 x64本機工具命令提示符」(或x86)。您可以使用此提示調用cmake,或者從您的正常提示中調用此提示,它將正確設置您的路徑。

REM Set up the include/lib paths of Visual Studio 
call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" amd64 

cd to_build_dir 

REM Call cmake with the right parameters 
"C:\Program Files\CMake\bin\cmake.exe" ....... 

REM Build the XYZ project 
MSBuild.exe SOLUTION_FILE.sln /t:XYZ ....... 

正如我寫的,我不知道它會改正錯誤,因爲我無法重現它。但是,我知道我的項目只有在使用正確的提示時纔會編譯。當我不使用它時,我會得到一些error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.