MinGW C compiler "not able to compile a simple test program" - makefile

I want to run MinGW as a C compiler. MinGW has been installed from Chocolatey. Invocation is from gitlab-runner through CMake. This fails with
$ cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DLIB_MAN=OFF -DCMAKE_INSTALL_PREFIX=C:\opt\x64 -B. ..
-- The C compiler identification is unknown
-- Check for working C compiler: C:/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe
-- Check for working C compiler: C:/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/ProgramData/chocolatey/bin/mingw32-make.exe cmTC_ffa53/fast && C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/mingw32-make -f CMakeFiles\cmTC_ffa53.dir\build.make CMakeFiles/cmTC_ffa53.dir/build
mingw32-make[1]: Entering directory 'C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ffa53.dir/testCCompiler.c.obj
C:\ProgramData\chocolatey\bin\x86_64-w64-mingw32-gcc.exe -o CMakeFiles\cmTC_ffa53.dir\testCCompiler.c.obj -c C:\gitlab-runner\builds\zjE1Mkfg\0\mlz\kww\build\CMakeFiles\CMakeTmp\testCCompiler.c
mingw32-make[1]: *** [CMakeFiles\cmTC_ffa53.dir\build.make:65: CMakeFiles/cmTC_ffa53.dir/testCCompiler.c.obj] Error 1
mingw32-make[1]: Leaving directory 'C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeTmp'
mingw32-make: *** [Makefile:120: cmTC_ffa53/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeOutput.log".
See also "C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeError.log".
ERROR: Job failed: exit status 1
From various web sources I understand that MinGW is bound to fail if sh.exe is present on the system [1]. However, sh.exe comes with several applications, among them Git and Visual Studio, which I cannot remove. Somewhere it's suggested to add -DCMAKE_SH="CMAKE_SH-NOTFOUND", which, however, has no effect.
I've seen a related question from 2015 [2], which however involves CLion. The only upvoted answer contains several broken links - altogether, that thread isn't helpful.
How to proceed? Is there a chance to work around the sh.exe problem?
Other advice on the web suggests to use -G "MSYS Makefiles". However, the CMake documentation [3] seems to rule this out: "not compatible with a Windows command prompt. To build under a Windows command prompt, use the MinGW Makefiles generator."
[1] https://stackoverflow.com/a/7411982/1017348
[2] CLion: Error:The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program
[3] https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html#generator:MSYS%20Makefiles per CMake 3.16.1

After long experimentation, I conclude that the problem comes from Chocolatey's packaging of MinGW. The problem is gone after I
uninstalled the MinGW package from Chocolatey,
reinstalled MinGW using the original MinGW installer,
installed the Ninja Chocolatey package,
inserted C:\MinGW\bin on top of PATH.
$ cmake -G "Ninja" -DLIB_MAN=OFF -DCMAKE_INSTALL_PREFIX=C:\opt\x64 -B. ..
-- The C compiler identification is GNU 8.2.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
Also note:
There is no need for -DCMAKE_C_COMPILER=...
I did not try hard to get -G "MinGW Makefile" working; -G Ninja works just fine.

The sh.exe is only a problem when you run CMake the first time when trying to generate the project. You can rerun CMake again and CMake will continue with normal processing to generate the project (tested in version 3.16). I saw a patch that removes this check and should be part of a future release of CMake.
It's already mentioned that gcc is installed incorrectly. That always seems to be the case when anyone mentions that gcc fails with an Error 1 message. It should be noted that Error 1 is not from CMake. CMake is just gathering the output from when it runs mingw32-make to build the sample project.
The first message in the output -- The C compiler identification is unknown is a pretty clear message that your compiler isn't working. All of the output for this step is in the log and error files that CMake generates in the build folder. You'll be able to see how it invoked the compiler and with which options and the output from the compiler.

Related

How to resolve linker path error when using home-brew clang 13 in CMake project on macOS 12

In order to make use of newer C++ 17 and 20 features, I want to switch from Apple clang to a homebrew installed vanilla clang. I installed it via brew install llvm.
When trying to build a minimal CMake based test project like
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ -G Ninja testProject
CMake fails with
-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang - broken
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/usr/local/opt/llvm/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/me/Projects/testProject/build/CLion/Debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/local/bin/ninja cmTC_d2d4b && [1/2] Building C object CMakeFiles/cmTC_d2d4b.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_d2d4b
FAILED: cmTC_d2d4b
: && /usr/local/opt/llvm/bin/clang -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_d2d4b.dir/testCCompiler.c.o -o cmTC_d2d4b && :
ld: library not found for -lSystem
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
So it seems that it fails to locate the correct library search path out of the box.
When trying to build a simple hello world program from the command line like
/usr/local/opt/llvm/bin/clang++ main.cpp -isysroot /Library/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk
It fails with even not finding some headers.
Supplying the header and library search path explicitly to the build command like
/usr/local/opt/llvm/bin/clang++ main.cpp -I"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" -L"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
makes it work. However, both are no solutions to make the built-in CMake compiler check work and they don't seem like the correct way to go.
Once this is working correctly, I'm furthermore interested in being able to compile ObjectiveC++ code which currently fails with even more errors.
I think I understand the problem that the compiler does not know the correct search paths, but I'm lacking some understanding about how it would normally figure out those search paths in a CMake project.
I finally managed to get it working by supplying a few linker flags through the LDFLAGS environment variable:
-L/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/usr/lib
In order to find the system libraries needed by the C compiler check
-L/usr/local/opt/llvm/lib
In order to find the C++ libraries as needed by the C++ compiler check
In order to successfully compile Objective-C code that links to Apple frameworks, I furthermore needed to add
-F/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks -lobjc
With those flags, I now can successfully build my projects. Still, I'm not 100% sure if this is the right way, especially if the libraries linked from /usr/local/opt/llvm/lib can be expected to be present on all target systems?

CLion + MinGW Test CMake run finished with errors

I'm new on this IDE, and programming on Windows, I've installed MinGW and added to enviroment path all is ok, I can compile and execute code from "cmd", but when I run CLion I have this error:
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/JetBrains/CLion 2017.3.1/bin/cmake/share/cmake-3.9/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:/Users/noName/AppData/Local/Temp/cmake_check_environment/_build/CMakeFiles/CMakeTmp
Run Build Command:"C:/MinGW/bin/mingw32-make.exe" "cmTC_2e43b/fast"
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_2e43b.dir\build.make
CMakeFiles/cmTC_2e43b.dir/build
mingw32-make.exe1: Entering directory
'C:/Users/noName/AppData/Local/Temp/cmake_check_environment/_build/CMakeFiles/CMakeTmp'
CMakeFiles\cmTC_2e43b.dir\build.make:64: recipe for target
'CMakeFiles/cmTC_2e43b.dir/testCCompiler.c.obj' failed
process_begin:
CreateProcess(C:\Users\noName\AppData\Local\Temp\make2428-1.bat,
C:\Users\noName\AppData\Local\Temp\make2428-1.bat, ...) failed.
make (e=2): El sistema no puede encontrar el archivo especificado.
mingw32-make.exe1: *** [CMakeFiles/cmTC_2e43b.dir/testCCompiler.c.obj]
Error 2
mingw32-make.exe1: Leaving directory
'C:/Users/noName/AppData/Local/Temp/cmake_check_environment/_build/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_2e43b/fast' failed
mingw32-make.exe: *** [cmTC_2e43b/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/noName/AppData/Local/Temp/cmake_check_environment/_build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/noName/AppData/Local/Temp/cmake_check_environment/_build/CMakeFiles/CMakeError.log".
Error code: 1
This is the photo. I think this is and error with CMake(?)
your windows 64bit and you can't write gcc.exe and g++.exe in windows 64 . you should try installing mingw-w64.
you can download this From here and installing this.
after that you should go in CLion setting -> build,Execution,deployment -> Toolchains
and configuration like this picture
and for installer mingw-w64 you should installer default option.
I encountered the same problem with mingw-32. Here is my solution.
First I removed all packages through MinGW Installer. Then as Jetbrains quick tutorial suggests I went to this page to download MingW-W64-builds. Installed it as x86_64. Under Toolchain | Environment clicked ... after the first dropdown slot, specified the folder called mingw64 under my installation. MinGW version should be "w64 5.0". This time no error report and Make, C compiler and C++ compiler were detected.
open the MinGW Installation Manger,and choose all the items under the path of All packages/MinGW/MinGW Base System to installation.
I keep going back to this question every now and then when I encounter the same error, although the cause of it in my cases is not present in any of the previous answers. In general, MinGW package (or CMake, whichever it is) does not like it when either it or file(s) we want it to work with is placed in a path with non-latin characters. Changing the directory of the project and / or MinGW installation solves the issue every time.

Can't compile restbed on Windows 7

I'm a the end with 16 hours of configure, installing, deleting, modifying and hit my keyboard many times....
I want to use restbed for plattform independent C++ programming, but I can't get build this stuff. I have Cygwin (download at 2017/04/24) installed (think for git or whatever creepy things), Code::Blocks with MinGW (16.01) and at least a seperate MinGW (also downloaded 2017/04/24) installation. Also I've Visual Studio 2012 Pro, 2015 and 2017 (long story) on a Windows 7 x64 Pro.
This is what I try and the results:
cloning recursivly with git in empty directory and following the instructions.
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=NO -DBUILD_SHARED=YES ..
Uhh.. success. I seems it using the gcc/g++ from Cygwin.
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
:
:
-- Configuring done
-- Generating done
-- Build files have been written to: /cygdrive/d/Entwicklung/C++/restbed/restbed/build
Nice! Now follows:
make -j install
After 7% working, it gives a bunch of warnings and failed:
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:755:5: warning: #warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. [-Wcpp]
# warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
^
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:756:5: warning: #warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line. [-Wcpp]
# warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line.
^
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:757:5: warning: #warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target). [-Wcpp]
# warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
^
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:781:5: error: #error You must add -D__USE_W32_SOCKETS to your compiler options.
I modifing config.hpp and add
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
The 'define bla' warnings dissapear, but now I should set '-D__USE_W32_SOCKETS'.
BUT WHERE?
After researching google I try to set a enviroment variable CPPFLAGS=-D__USE_W32_SOCKETS, but this change nothing!
OK, now I want give MinGW a chance, but how get I rid of this penetrant Cygwin, without deinstalling and get mess with other software?
Cool, should I set some enviroment variables....
Clean up the build-Directory and set CC and CXX as mentioned in cmake output.
SET CC=D:/MinGW/bin/gcc.exe
SET CXX=D:/MinGW/bin/g++.exe
Checking my PATH variable and adding ";D:\MinGW\mysys\1.0\bin;D:\MinGW\bin"
Now use cmake bla.. again...but... but... WHAT?
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
CMake Error at CMakeLists.txt:4 (project):
The CMAKE_C_COMPILER:
D:/MinGW/bin/gcc.exe
is not a full path and was not found in the PATH.
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.
CMake Error at CMakeLists.txt:4 (project):
The CMAKE_CXX_COMPILER:
D:/MinGW/bin/g++.exe
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_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 "/cygdrive/{my_path_to}/restbed/restbed/build/CMakeFiles/CMakeOutput.log".
With Cygwin cmake says, I use gcc/g++ in version GNU 5.4.0. On the other hand, it detects the correct MinGW version as 5.3.0, but can't find it? Hu?
What can I do to get this library work under Windows 7?
EDIT BEGIN
To build makefiles for Code::Blocks, the -G parameter doesn't work. I try some combinations, but always say:
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=NO -DBUILD_SHARED=YES -G "CodeBlocks" ..
CMake Error: Could not create named generator CodeBlocks
Generators
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
:
:
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=NO -DBUILD_SHARED=YES -G "CodeBlocks - Ninja" ..
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Now this (many censored words) thing want to know the cmake-make?
My fault.... don't think about, what I've installed.
"CodeBlocks - Unix Makefiles" works as expected for generating project file, but can't compile under Code::Blocks. I changed compiler for project in 'Build options' to Cygwin, but says:
Execution of '/usr/bin/make.exe -j8 -f "/cygdrive/d/{my_path_to}/restbed/restbed/build/Makefile" VERBOSE=1 all' in 'D:\{my_path_to}\restbed\restbed\build' failed.
...and nothing more. Think it has to do with "Unix Makefile" under Windows.
EDIT END
I'm out of knowledge what to do, what to set, to delete, to modify, configure, aaaargh.
My last hope is, that someone has the big hint, a good idea or a workaround.
Thanks in advance.
Restbed can build with Visual Studio 2015/2017, why not use the native toolchain for that platform?

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.

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

Resources