1

I have a simple C++ test project and wrote my CMakeLists.txt file as follows;

 cmake_minimum_required(VERSION 2.8)

 set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc")
 set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++")

 project(simpleTest)
 add_executable(main main.cpp)

When i try to run CMake GUI an set generator to MinGW i get the following error message:

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:61 (message):
  The C compiler "C:/MinGW/bin/gcc" 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:7 (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!

I'm on Windows 7 64 bit and i confirmed on cmd that; G++ --version gives G++ (GCC) 4.6.1.

What am I doing wrong?

Amani
  • 16,245
  • 29
  • 103
  • 153

2 Answers2

3

Sorry but this looks like the compiler is not installed where you specified. Also see here why you should avoid setting the compiler in CMakeLists.txt

So I'd remove those, clear the cmake cache, set the environment variables CC and CXX before calling CMake and try again.

Community
  • 1
  • 1
Christian Rapp
  • 1,853
  • 24
  • 37
  • you are right about not setting the compiler in CMakeLists.txt but the checked again and again the compiler are installed where I specified. – Amani Feb 24 '13 at 16:03
  • Did you remove the two lines and cleared the cmake cache? Also I added to my answer that you should try to set the environment variables before you call cmake – Christian Rapp Feb 24 '13 at 16:15
2

I think your problem lies in the path string. Try this:

set(CMAKE_C_COMPILER "C:\\MinGW\\bin\\gcc")
set(CMAKE_CXX_COMPILER "C:\\MinGW\\bin\\g++")

Alternatively, you can also set your compilers in the CMake GUI. After you click on generate, choose the option "Specify native compilers" and set or browse to the correct location.

ToniBig
  • 836
  • 6
  • 21
  • 1
    The problem (as I discovered and from other suggestions) is not what you pointed out, but rather the fact that sh.exe is in my system PATH. This can also be proven by the fact that if I set generator to "MSYS Makefiles" it works even without setting CMAKE_C_COMPILER or CMAKE_CXX_COMPiLER in the CMakeLists.txt file. – Amani Feb 26 '13 at 15:56