簡體   English   中英

使用Microsoft Visual C ++構建工具進行CMake

[英]CMake with Microsoft Visual C++ Build Tools

編輯:已將此發布到他們的問題跟蹤器,並與一些CMake開發人員一起介紹,這實際上不是一個CMake問題。 我的MSBuild安裝導致它返回“操作已成功完成”。 錯誤。 在整個問題上仍然沒有解決問題,但這縮小了潛在的原因。


我正在嘗試使用MS Visual C ++ Build Tools 2015在Windows上構建一個CMake項目(注意:不完整的Visual Studio)。 但是,CMake顯然無法找到cl.exe

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 ++ shell(將工具添加到路徑)時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... ]

這就是我正在運行cmake ..的相同環境cmake ..所以cl.exe絕對是CMH發現的PATH。

編輯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 Build Tools。 有任何想法嗎?

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

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

我不確定我為你The operation completed successfully問題帶來了解決方案,但我能夠使用cmake 3.8.1和C ++ 2015 BuildTools編譯一個[大]現實生活項目。

訣竅就是使用“VS2015 x64 Native Tools命令提示符”(或x86)。 您可以使用此提示調用cmake,也可以從正常提示中call此提示,它將正確設置您的路徑。

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. 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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM