Running CMake on Windows - windows-7

I am currently trying to get CMake to run on my Windows 7 (64-bit) system. I want to compile TagLib for later use with a Qt application I am working on. I would like to compile it with MinGW (not Visual C++ as in this other question).
I download the installer (cmake-2.8.3-win32-x86.exe) and install it (I also opt to add CMake to my path). I then go to the directory why the CMakeLists.txt file is and run cmake .. It then gives me this giant error.
C:\Users\Joel\Downloads\taglib-1.6.3>cmake .
CMake Warning at CMakeLists.txt:1 (project):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Warning at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:
28 (ENABLE_LANGUAGE):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
CMakeLists.txt:1 (project)
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found. Please set CMAKE_RC_COM
PILER to a valid compiler path or name.
-- Check for CL compiler version
-- Check for CL compiler version - failed
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - yes
-- Using FREE VC TOOLS, NO DEBUG available
-- Check for working C compiler: cl
CMake Warning at CMakeLists.txt:2 (PROJECT):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
CMake Warning at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:
28 (ENABLE_LANGUAGE):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeRCInformation.cmake:22
(GET_FILENAME_COMPONENT):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:28 (ENABLE_LANG
UAGE)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage
CMake Error: your C compiler: "cl" was not found. Please set CMAKE_C_COMPILER to a valid compiler
path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: cl -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52
(MESSAGE):
The C compiler "cl" is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
CMake Error: your C compiler: "cl" was not found. Please set CMAKE_C_COMPILER to a valid compiler
path or name.
CMake Error: your CXX compiler: "cl" was not found. Please set CMAKE_CXX_COMPILER to a valid compi
ler path or name.
-- Configuring incomplete, errors occurred!
C:\Users\Joel\Downloads\taglib-1.6.3>
I was kind of surprised that it failed so hard out of the box, considering it advertises itself as a cross-platform make.
I tried setting INCLUDE, LIB, and LIBPATH (Windows environment variables) all to my MinGW binaries directory (C:\MinGW\bin) but it's still giving me the same error. I also tried setting CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to the location of g++ (C:\MinGW\bin\g++).
Does anyone know what's going on here?
SOLUTION:
Per tibur's suggestion, I ran the cmake GUI to create the make files.
I then went into the directory taglib directory and ran mingw32-make.exe to do the actual build.

The default generator for Windows seems to be set to NMAKE. Try to use:
cmake -G "MinGW Makefiles"
Or use the GUI, and select MinGW Makefiles when prompted for a generator. Don't forget to cleanup the directory where you tried to run CMake, or delete the cache in the GUI. Otherwise, it will try again with NMAKE.

There is a vcvars32.bat in your Visual Studio installation directory. You can add call cmd.exe at the end of that batch program and launch it. From that shell you can use CMake or cmake-gui and cl.exe would be known to CMake.

the command that worked for me is:
$ cmake -G "MSYS Makefiles" ..
I'm working on MSYS2/Win10 compiling a QT5 app #64bit (using the MINGW64 shell)

Use: cmake --build
after cmake -G "MinGW Makefiles"

Related

Can't run Cmake on windows with MinGW and git bash

I try to build gitql.
I've installed go, CMake and MinGW, and tried to make them work under git bash, but when I call cmake in gitql directory I get this error:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:14 (PROJECT):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeOutput.log".
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeError.log".
make: *** [prepare] B▒▒d 1
So I've tried to point to gcc from mingw using:
export CC=/c/MinGW/bin/gcc.exe
and when I run make I get this error:
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_14ff0\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_14ff0\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_14ff0\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:14 (PROJECT)
-- Configuring incomplete, errors occurred!
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeOutput.log".
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeError.log".
make: *** [prepare] B▒▒d 1
How can I inform cmake to use make instead of nmake? I have make installed in C:\Program Files (x86)\GnuWin32\bin which is in $PATH.
I've also try to call cmake -G "MinGW Makefiles" but I've got this error:
CMake Error: The source directory "C:/Go/src/github.com/cloudson/gitql" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
cmake -G "MinGW Makefiles" is effectively the right command to inform CMake you want to use MinGW.
To be complete, you should create a separate folder, let's call it build, and call cmake from it to make an out-of-source build:
cd /path/to/build
cmake -G "MinGW Makefiles" /path/to/CMakeLists.txt
The problem here is gitql doesn't provide any CMakeLists.txt file in the repository, so you just can't use CMake to build it, unless you create your own project file. You can try from the given Makefile, and propose it as a pull request.

cmake: problems with out of tree build

With my current CMakeLists.txt files, I can build my project with:
sourceDir> cmake -G "MinGW Makefiles" .
from the source directory.
However I cannot get an out-of-tree build:
buildDir> cmake -G "MinGW Makefiles" ..\MyProg
This is the error I get from cmake:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (MESSAGE):
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:16 (project)
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:S:/MyProg/build/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:S:/MyProg/build/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
That does not make sense those errors come from the environment being setup different. Are both commands being run from the exact same shell? Also, once you configure in-source, you can not do an out of source build. So, to test try this:
mkdir newsource; checkout your source here
mkdir ../build
cd ../build
cmake -G"MinGW Makefiles" ../newsource
mkdir insource; checkout out your source here
cmake -G"MinGW Makefiles" .
Do both of these from the exact same shell.
I found a dirty fix to my problem:
buildDir> cmake -G "MinGW Makefiles" ..\MyProg\
buildDir> cmake -G "MinGW Makefiles" ..\MyProg\
The first time I get the error shown in my question. The second time everything goes as it should.
Let me know if you have a better, more logic solution.
I think you have to remove "MinGW\msys\1.0\bin" from your windows PATH environment variable.

Unable to specify the compiler with CMake

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

CMake with MinGW and Eclipse CDT

I'm trying to compile OpenCV with Cmake on Windows 7 (64-bit). It is to be used with Eclipse and CDT, for which I read somewhere that youhave to specify Unix Makefiles regardless of the compiler.
Now, given that I have cygwin as well (for Android NDK stuff), I first tried using its compilers, and I successfully configure CMake and generate makefiles, but only get to 63% of compiling, when OpenCV spits an error (about ffmpeg and HMODULE). So I switched to MinGW (HelloWorld with it was also a pain, I had to specify a full path to MinGW g++ regardless of the PATH variable setting), but now I cannot even configure CMake. I get the following error:
The C compiler identification is GNU
The CXX compiler identification is GNU
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found. Please set CMAKE_RC_COMPILER to a valid compiler path or name.
Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeRCInformation.cmake:22 (GET_FILENAME_COMPONENT):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-GNU.cmake:59 (enable_language)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-GNU-C.cmake:1 (include)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:56 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:47 (project)
Configuring incomplete, errors occurred!
If anyone has any idea what might be a problem (conflict with cygwin shell?), I'd appreciate any input. Thanks in advance!
We ran into the same problem with the "Unix Makefiles" Generator. We solved it by using the "MSYS Makefiles" generator (Msys is a shell environment around MinGW, like [a very small] cygwin).
This error message text:
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found.
Please set CMAKE_RC_COMPILER to a valid compiler path or name.
indicates that "windres" (for mingw and cygwin gcc-based build trees) is not in the PATH.
windres support, to compile Windows resource (*.rc) files was recently added in CMake 2.8.4. Perhaps windres is not available in your MinGW environment?

cmake doesn't work in windows XP

I'm new with cmake,just installed it and following this article:
http://www.cs.swarthmore.edu/~adanner/tips/cmake.php
D:\Works\c\cmake\build>cmake ..
-- Building for: NMake Makefiles
CMake Warning at CMakeLists.txt:2 (project):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Warning at D:/Tools/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:32 (ENABLE_LANGUAGE):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
Call Stack (most recent call first):
D:/Tools/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:58 (INCLUDE)
CMakeLists.txt:2 (project)
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found. Please set CMAKE_RC_COMPILER to a valid compiler path or name.
-- Check for CL compiler version
-- Check for CL compiler version - failed
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - yes
-- Using FREE VC TOOLS, NO DEBUG available
-- Check for working C compiler: cl
CMake Warning at CMakeLists.txt:2 (PROJECT):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
CMake Warning at D:/Tools/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:32 (ENABLE_LANGUAGE):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
Call Stack (most recent call first):
D:/Tools/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:58 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error at D:/Tools/CMake 2.8/share/cmake-2.8/Modules/CMakeRCInformation.cmake:22 (GET_FILENAME_COMPONENT):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
D:/Tools/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:32 (ENABLE_LANGUAGE)
D:/Tools/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:58 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage
CMake Error: your C compiler: "cl" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: cl -- broken
CMake Error at D:/Tools/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "cl" is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
CMake Error: your C compiler: "cl" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "cl" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
What are the complete requirement to use cmake successfully in windows XP?I've already installed Visual Studio under D:\Tools\Microsoft Visual Studio 9.0
First of all, I have to confess that I don't know cmake.
To use the NMake generator, cmake
must be run from a shell that can use
the compiler cl from the command
line. This environment does not
contain INCLUDE, LIB, or LIBPATH,
and these must be set for the cl
compiler to work.
The error above means that the proper locations to your C/C++ compiler's headers and libraries could not be found by cmake.
Instead of running cmake from the Command Prompt, try running cmake from the Visual Studio 2008 Command Prompt. You can find it under Start > Programs > Microsoft Visual Studio 2008 > Visual Studio Tools) or vcvarsall.bat in the folder *Microsoft Visual Studio 9.0\VC*. The visual Studio 2008 Command Prompt should set all these environment variables for you automatically so that cmake knows where to find the necessary files that it needs.
The Command Prompt will start in your Visual Studio folder, so you'll have to type the following commands to switch to your source folder and start cmake.
D:
cd D:\Works\c\cmake\build>
cmake
I hope this helps you.
I had similar issues on Win7, and was getting the same error - The C compiler "cl.exe" is not able to compile a simple test program.
The solution that worked for me :
On Windows Donot run cmake on the cygwin terminal.
Run it from the command prompt, AND also ensure that you have admin rights, In windows 7 you can start command prompt as administrator by going to Start->All programs->Accessories-> (Right Click on Command Prompt) and Select "Run as administrator"
Then run 'cmake <your source>' Worked like a charm for me.

Resources