Cai*_*tes 90 c++ gcc cmake visual-studio visual-studio-2015
我正在尝试用CMake制作一个Visual Studio解决方案来编译最新版本的aseprite并且CMake一直给我:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
Run Code Online (Sandbox Code Playgroud)
我已经下载了GCC,我正在使用Visual Studio 2015.
我正在学习本教程:
Flo*_*ian 90
那些错误消息
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".
Run Code Online (Sandbox Code Playgroud)
要么
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!
Run Code Online (Sandbox Code Playgroud)
只是意味着CMake无法找到你的C/CXX编译器来编译一个简单的测试程序(CMake在检测你的构建环境时尝试的第一件事).
查找问题的步骤取决于您要生成的构建环境.以下教程是Stack Overflow上的答案集合,以及我在Microsoft Windows 7/8/10和Ubuntu 14.04上使用CMake的一些经验.
前提条件
你有一个干净的构建目录(因为CMake会从最后一次尝试中缓存内容),例如作为源树的子目录
Windows cmd.exe
> rmdir /s /q VS2015
> mkdir VS2015
> cd VS2015
Run Code Online (Sandbox Code Playgroud)
Bash shell
$ rm -rf MSYS
$ mkdir MSYS
$ cd MSYS
Run Code Online (Sandbox Code Playgroud)
并确保您的命令shell指向新创建的二进制输出目录.
一般事情你可以/应该尝试
CMake能否找到并运行任何/您的默认编译器?没有给发电机运行
> cmake ..
-- Building for: Visual Studio 14 2015
...
Run Code Online (Sandbox Code Playgroud)
如果正确确定要使用的发电机就完美 - 就像这里一样 Visual Studio 14 2015
实际上失败了什么?
在上一个构建输出目录中,查看CMakeFiles\CMakeError.log
对您有意义的任何错误消息,或尝试打开/编译在CMakeFiles\[Version]\CompilerIdC
| 生成的测试项目 CompilerIdCXX
直接从命令行(在错误日志中找到).
CMake找不到Visual Studio
尝试选择正确的发电机版本:
> cmake --help
> cmake -G "Visual Studio 14 2015" ..
Run Code Online (Sandbox Code Playgroud)如果这没有帮助,请尝试首先设置Visual Studio环境变量(路径可能会有所不同):
> "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
> cmake ..
Run Code Online (Sandbox Code Playgroud)
或使用//Developer Command Prompt for VS2015
下的Windows开始菜单中的快捷方式(感谢@Antwane提示).All Programs
Visual Studio 2015
Visual Studio Tools
背景:CMake确实支持所有Visual Studio版本和口味(Express,Community,Professional,Premium,Test,Team,Enterprise,Ultimate等).为了确定编译器的位置,它使用搜索注册表(例如at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[Version];InstallDir
),系统环境变量和 - 如果其他人都没有提出某些东西 - 的组合 - 明显地尝试调用编译器.
CMake找不到GCC(MinGW/MSys)
你启动MSys bash
shell,msys.bat
然后尝试直接调用gcc
$ gcc
gcc.exe: fatal error: no input files
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
它确实发现gcc
并且抱怨我没有给它任何参数来使用它.
所以以下应该有效:
$ cmake -G "MSYS Makefiles" ..
-- The CXX compiler identification is GNU 4.8.1
...
$ make
Run Code Online (Sandbox Code Playgroud)
如果未找到GCC,则调用export PATH=...
添加编译器路径(请参阅如何在CMake脚本中设置PATH环境变量?)并再试一次.
如果它仍然无法正常工作,请尝试CXX
通过导出直接设置编译器路径(路径可能会有所不同)
$ 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
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅如何为CMake指定新的GCC路径
注意:使用"MinGW Makefile"生成器时,必须使用mingw32-make
随MinGW分发的程序
还是行不通?那真是怪了.请确保编译器在那里并且它具有可执行权限(另请参阅上面的前置条件章节).
否则,CMake的最后一招是不尝试任何编译器搜索本身并直接设置CMake的内部变量
$ cmake -DCMAKE_C_COMPILER=/c/MinGW/bin/gcc.exe -DCMAKE_CXX_COMPILER=/c/MinGW/bin/g++.exe ..
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅Cmake不承认-D CMAKE_CXX_COMPILER = g ++和Cmake错误设置编译器
或者,也可以cmake-gui.exe
在Windows 上设置这些变量.看Cmake找不到编译器
背景:与Visual Studio大致相同.CMake支持各种GCC口味.它搜索环境变量(CC,CXX等)或只是尝试调用编译器.此外,它会检测到任何前缀(当交叉编译),并试图将其添加到GNU编译器工具链的所有的binutils( ,ar
,ranlib
,strip
,ld
,nm
,objdump
和objcopy
).
Wim*_*den 18
安装Visual Studio 15 2017后,这发生在我身上.
Visual Studio 14 2015的C++编译器不是问题.这似乎是Windows 10 SDK的一个问题.
将Windows 10 SDK添加到Visual Studio 14 2015为我解决了这个问题.
请参见附件截图.
Vis*_*hnu 17
对于Ubuntu,请安装以下内容:
sudo apt-get update && sudo apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)
小智 12
使用CMake时我也遇到过这个错误:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2015中的MSDN库文章Visual C++中的"警告"框为我提供了所需的帮助.
Visual Studio 2015默认情况下不附带C++.因此,创建一个新的C++项目将提示您下载必要的C++组件.
我对 CMake 有同样的错误。就我而言,我在初始 CMake 对话框中使用了错误的 Visual Studio 版本,我们必须在其中选择 Visual Studio 编译器。
然后我将其更改为“Visual Studio 11 2012”并且一切正常。(我的 PC 上有 Visual Studio Ultimate 2012 版本)。通常,尝试在初始 CMake 配置对话框中输入旧版本的 Visual Studio 版本。
我在构建 libgit2-0.23.4 时遇到了这个问题。对我来说,问题是 VS2015 没有安装 C++ 编译器和相关包,因此“C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat”文件丢失,Cmake 无法找到编译器。
我尝试在 Visual Studio 2015 GUI ( C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe ) 中手动创建一个 C++ 项目,在创建项目时,我得到了下载 C++ 的提示& 相关的包。
下载所需的包后,我可以看到 vcvarsall.bat & Cmake 能够找到编译器并成功执行,并显示以下日志:
C:\Users\aksmahaj\Documents\MyLab\fritzing\libgit2\build64>cmake ..
-- Building for: Visual Studio 14 2015
-- The C compiler identification is MSVC 19.0.24210.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio 14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- zlib was not found; using bundled 3rd-party sources.
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of
the default search path.
-- Looking for futimens
-- Looking for futimens - not found
-- Looking for qsort_r
-- Looking for qsort_r - not found
-- Looking for qsort_s
-- Looking for qsort_s - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
-- Found PythonInterp: C:/csvn/Python25/python.exe (found version "2.7.1")
-- Configuring done
-- Generating done
-- Build files have been written to:
C:/Users/aksmahaj/Documents/MyLab/fritzing/libgit2/build64
Run Code Online (Sandbox Code Playgroud)
这在Ubuntu 17.10(Artful Aardvark)中对我有效:
apt-get update
apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
226572 次 |
最近记录: |