問題描述
我正在嘗試使用 CMake 制作 Visual Studio 解決方案來編譯最新版本的 aseprite,而 CMake 不斷給我:
I'm trying make a Visual Studio solution with CMake to compile the latest version of aseprite and CMake keeps giving me the:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
我已經下載了 GCC,我正在使用 Visual Studio 2015.
I've already downloaded GCC, and I'm using Visual Studio 2015.
我正在學習本教程:
https://github.com/aseprite/aseprite/blob/master/安裝.md
推薦答案
那些錯誤信息
CMake Error at ... (project):
No CMAKE_C_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also ".../CMakeFiles/CMakeOutput.log".
See also ".../CMakeFiles/CMakeError.log".
或
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.
Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
...
-- Configuring incomplete, errors occurred!
只是意味著 CMake 無法找到您的 C/CXX 編譯器來編譯一個簡單的測試程序(這是 CMake 在檢測您的構建環境時嘗試的第一件事).
just mean that CMake was unable to find your C/CXX compiler to compile a simple test program (one of the first things CMake tries while detecting your build environment).
查找問題的步驟取決于您要生成的構建環境.以下教程是 StackOverflow 上的一系列答案以及我自己在 Microsoft Windows 7/8/10 和 Ubuntu 14.04 上使用 CMake 的一些經驗.
The steps to find your problem are dependent on the build environment you want to generate. The following tutorials are a collection of answers here on Stack Overflow and some of my own experiences with CMake on Microsoft Windows 7/8/10 and Ubuntu 14.04.
前提
- 您已經安裝了編譯器/IDE,它能夠一次編譯任何其他程序(直接無需 CMake)
- 你例如可能有 IDE,但可能沒有安裝編譯器或支持框架本身,如 使用 CMake 為 VS 2017 生成解決方案的問題 或 如何告訴 CMake 在 Windows 上使用 Clang?
您有一個干凈的構建目錄(因為 CMake 確實緩存了上次嘗試的內容)例如作為源代碼樹的子目錄
You have a clean build directory (because CMake does cache things from the last try) e.g. as sub-directory of your source tree
Windows cmd.exe
> rmdir /s /q VS2015 > mkdir VS2015 > cd VS2015
Bash shell
$ rm -rf MSYS $ mkdir MSYS $ cd MSYS
并確保您的命令外殼指向您新創建的二進制輸出目錄.
and make sure your command shell points to your newly created binary output directory.
你可以/應該嘗試的一般事情
CMake 是否能夠找到并運行任何/您的默認編譯器?運行不給發電機
Is CMake able find and run with any/your default compiler? Run without giving a generator
> cmake .. -- Building for: Visual Studio 14 2015 ...
如果它正確確定要使用的生成器就完美了 - 就像這里
Visual Studio 14 2015
Perfect if it correctly determined the generator to use - like here
Visual Studio 14 2015
實際上失敗的是什么?
在之前的構建輸出目錄中,查看
CMakeFilesCMakeError.log
以獲取對您有意義的任何錯誤消息,或者嘗試打開/編譯在CMakeFiles[Version 生成的測試項目]CompilerIdC
|CompilerIdCXX
直接從命令行(在錯誤日志中找到).In the previous build output directory look at
CMakeFilesCMakeError.log
for any error message that make sense to you or try to open/compile the test project generated atCMakeFiles[Version]CompilerIdC
|CompilerIdCXX
directly from the command line (as found in the error log).CMake 找不到 Visual Studio
盡量選擇正確的生成器版本:
> cmake --help > cmake -G "Visual Studio 14 2015" ..
如果這沒有幫助,請先嘗試設置 Visual Studio 環境變量(路徑可能會有所不同):
If that doesn't help, try to set the Visual Studio environment variables first (the path could vary):
> "c:Program Files (x86)Microsoft Visual Studio 14.0VCvcvarsall.bat" > cmake ..
或使用
Developer Command Prompt for VS2015
快捷方式,在All Programs
/Visual Studio 2015
/下的 Windows 開始菜單中>Visual Studio 工具
(感謝 @Antwane 的提示).or use the
Developer Command Prompt for VS2015
short-cut in your Windows Start Menu underAll Programs
/Visual Studio 2015
/Visual Studio Tools
(thanks at @Antwane for the hint).背景:CMake 支持所有 Visual Studio 版本和風格(Express、Community、Professional、Premium、Test、Team、Enterprise、Ultimate 等).為了確定編譯器的位置,它結合了搜索注冊表(例如在
HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio[Version];InstallDir
)、系統環境變量和 - 如果沒有其他確實想出了一些辦法 - 顯然是嘗試調用編譯器.Background: CMake does support all Visual Studio releases and flavors (Express, Community, Professional, Premium, Test, Team, Enterprise, Ultimate, etc.). To determine the location of the compiler it uses a combination of searching the registry (e.g. at
HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio[Version];InstallDir
), system environment variables and - if none of the others did come up with something - plainly try to call the compiler.CMake 找不到 GCC (MinGW/MSys)
您使用
msys.bat
啟動 MSysbash
shell,然后嘗試直接調用gcc
You start the MSys
bash
shell withmsys.bat
and just try to directly callgcc
$ gcc gcc.exe: fatal error: no input files compilation terminated.
在這里它確實找到了
gcc
并抱怨我沒有給它任何參數.Here it did find
gcc
and is complaining that I didn't gave it any parameters to work with.所以以下應該有效:
$ cmake -G "MSYS Makefiles" .. -- The CXX compiler identification is GNU 4.8.1 ... $ make
如果未找到 GCC,請調用
export PATH=...
以添加您的編譯器路徑(請參閱如何在 CMake 腳本中設置 PATH 環境變量?) 然后再試一次.If GCC was not found call
export PATH=...
to add your compilers path (see How to set PATH environment variable in CMake script?) and try again.如果還是不行,嘗試直接通過導出設置
CXX
編譯器路徑(路徑可能會有所不同)If it's still not working, try to set the
CXX
compiler path directly by exporting it (path may vary)$ export CC=/c/MinGW/bin/gcc.exe $ export CXX=/c/MinGW/bin/g++.exe $ cmake -G "MinGW Makefiles" .. -- The CXX compiler identification is GNU 4.8.1 ... $ mingw32-make
更多細節參見如何為CMake指定新的GCC路徑
注意:當使用MinGW Makefiles"生成器時,你必須使用MinGW分發的
mingw32-make
程序Note: When using the "MinGW Makefiles" generator you have to use the
mingw32-make
program distributed with MinGW還是不行?這很奇怪.請確保編譯器在那里并且它具有可執行權限(另請參閱上面的前提條件章節).
Still not working? That's weird. Please make sure that the compiler is there and it has executable rights (see also preconditions chapter above).
否則 CMake 的最后一招是不要嘗試任何編譯器搜索本身并直接設置 CMake 的內部變量
Otherwise the last resort of CMake is to not try any compiler search itself and set CMake's internal variables directly by
$ cmake -DCMAKE_C_COMPILER=/c/MinGW/bin/gcc.exe -DCMAKE_CXX_COMPILER=/c/MinGW/bin/g++.exe ..
有關更多詳細信息,請參閱Cmake 不尊重 -D CMAKE_CXX_COMPILER=g++ 和 Cmake 錯誤設置編譯器
For more details see Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++ and Cmake error setting compiler
或者,這些變量也可以在 Windows 上通過
cmake-gui.exe
設置.請參閱Cmake 找不到編譯器Alternatively those variables can also be set via
cmake-gui.exe
on Windows. See Cmake cannot find compiler背景:與 Visual Studio 非常相似.CMake 支持各種 GCC 風格.它搜索環境變量(CC、CXX 等)或只是嘗試調用編譯器.此外,它會檢測任何前綴(當 交叉編譯 時)并嘗試將其添加到所有 binutilsGNU 編譯器工具鏈(
ar
、ranlib
、strip
、ld
、nm
、objdump
和objcopy
).Background: Much the same as with Visual Studio. CMake supports all sorts of GCC flavors. It searches the environment variables (CC, CXX, etc.) or simply tries to call the compiler. In addition it will detect any prefixes (when cross-compiling) and tries to add it to all binutils of the GNU compiler toolchain (
ar
,ranlib
,strip
,ld
,nm
,objdump
, andobjcopy
).這篇關于CMakeLists.txt:30 (project) 中的 CMake 錯誤:找不到 CMAKE_C_COMPILER的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!