可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying make a Visual Studio solution with Cmake to compile the latest version of aseprite and the cmake keeps giving me the :
No CMAKE_C_COMPILER could be found. No CMAKE_CXX_COMPILER could be found.
I've already downloaded gcc and i'm using visual studio 2015.
I'm following this tutorial /
https://github.com/aseprite/aseprite/blob/master/INSTALL.md
I've been searching for about 3 hours and no solution on internet fitted.
回答1:
Those error messages
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".
or
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!
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).
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 StackOverflow and some of my own experiences with CMake on MS Windows 7/8/10 and Ubuntu 14.04.
Preconditions
- You have installed the compiler/IDE and it was able to once compile any other program (directly without CMake)
- You have the latest CMake version
- You have access rights on the drive you want CMake to generate your build environment
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.
General things you can/should try
Is CMake able find and run with any/your default compiler? Run without giving a generator
> cmake .. -- Building for: Visual Studio 14 2015 ...
Perfect if it correctly determined the generator to use - like here Visual Studio 14 2015
What was it that actually failed?
In the previous build output directory look at CMakeFiles\CMakeError.log
for any error message that make sense to you or try to open/compile the test project generated at CMakeFiles\[Version]\CompilerIdC
|CompilerIdCXX
directly from the command line (as found in the error log).
CMake can't find Visual Studio
Try to select the correct generator version
> cmake --help > cmake -G "Visual Studio 14 2015" ..
If that doesn't help try to set the VS environment variables first (the path could vary)
> "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" > cmake ..
or use the Developer Command Prompt for VS2015
short-cut in your Windows Start Menu under All Programs
/Visual Studio 2015
/Visual Studio Tools
(thanks at @Antwane for the hint)
Background: CMake does support all Visual Studio releases and flavors (Express, Community, Professional, Premium, Test, Team, Enterprise, Ultimate, ...). To determine the location of the compiler it uses a combination of searching the registry (e.g. at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[Version];InstallDir
), system environment variables and - if none of the others did come up with something - plainly try to call the compiler.
CMake can't find GCC (MinGW/MSys)
You start the MSys bash
shell with msys.bat
and just try to directly call gcc
$ gcc gcc.exe: fatal error: no input files compilation terminated.
Here it did find gcc
and is complaining that I didn't gave it any parameters to work with.
So the following should work:
$ cmake -G "MSYS Makefiles" .. -- The CXX compiler identification is GNU 4.8.1 ... $ make
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.
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
For more details see how to specify new gcc path for cmake
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).
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 ..
For more details see Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++ and Cmake error setting compiler
Alternatively those variables can also be set via cmake-gui.exe
on Windows. See Cmake cannot find compiler
Background: Much the same as with Visual Studio. CMake supports all sorts of GCC flavors. It searches the environment variables (CC, CXX, ...) 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
, objcopy
).
回答2:
I also experienced this error when working with Cmake
No CMAKE_C_COMPILER could be found. No CMAKE_CXX_COMPILER could be found.
The 'warning' box in this MSDN Library article https://msdn.microsoft.com/en-us/library/60k1461a.aspx gave me the help that I needed.
Visual Studio 2015 doesn't come with c++ installed by default. So, creating a new c++ project will prompt you to download the necessary c++ components.
回答3:
I ran into this issue while building libgit2-0.23.4. For me the problem was that C++ compiler & related packages were not installed with VS2015, therefore "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" file was missing and Cmake wasn't able to find the compiler.
I tried manually creating a C++ project in the Visual Studio 2015 GUI (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe) and while creating the project, I got a prompt to download the C++ & related packages.
After downloading required packages, I could see vcvarsall.bat & Cmake was able to find the compiler & executed successfully with following log:
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
回答4:
I had the same errors with CMake. In my case, I have used the wrong visual studio version in initial CMake dialog where we have to select the visual studio compiler. Then I changed it as "Visual Studio 11 2012" and things work. (I have Visual Studio Ultimate 2012 version in my pc). In general, try giving an older version of Visual studio version in initial CMake configuration dialog.
回答5:
This happend to me after I installed Visual Studio 15 2017.
The c++ compiler for Visual Studio 14 2015 was not the problem. It seemed to be a problem with the Windows 10 sdk.
Adding the Windows10 sdk's to Visual Studio 14 2015 solved the problem for me.
See attached screenshot.
回答6:
Make sure you have selected the correct version of Visual Studio. This is trickier than it seems because Visual Studio 2015 is actually Visual Studio 14, and similarly Visual Studio 2012 is Visual Studio 11. I had incorrectly selected Visual Studio 15 which is actually Visual Studio 2017, when I had 2015 installed.
回答7:
None of the solutions here solves my problem, only when I install windows update for universal C runtime.
Now CMAKE is working and no more link hangs from visual studio.
https://support.microsoft.com/en-us/help/3118401/update-for-universal-c-runtime-in-windows
回答8:
for ubuntu please install below things:
sudo apt-get update && sudo apt-get install build-essential
回答9:
I updated visual studio 2015 update 2 to visual studio 2015 update 3 and it solved my problem.
回答10:
I had the same issue with cmake-gui (No CMAKE_CXX_COMPILER could be found.
), while running cmake from the command line worked fine. After manually adding the entries
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
it worked for me.