Error while compiling Cmake project

1

I'm having the following problem when trying to build a project using CMake:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):

I'm running the following: cmake .

The error also says that I should try to set the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER environment variables to the compiler path, so I did. I set the variables to C:\MinGW\bin\gcc.exe and C:\MinGW\bin\g++.exe , respectively.

The error has persisted.

My CMakeLists file contains the following:

cmake_minimum_required(VERSION 2.8.9)
project (hello)
add_executable(hello helloworld.cpp)

I have no knowledge of CMake, so consider that I may have forgotten some basic step. Does anyone have any idea what might be causing the problem?

    
asked by anonymous 11.03.2017 / 17:21

2 answers

2

I discovered what I was doing wrong. I'm not sure, however, why it was not working.

I was not selecting the correct generator, and the following command solved my problem:

cmake -G "MinGW Makefiles" ..

From there, I was able to build the project as expected.

    
13.03.2017 / 15:12
0

It seems like it is not finding the C Compiler on your system. It may be that your path variables are not correct.

To verify that the variables have been set correctly, open your command prompt and call the compiler C. I can not remember which command to call gcc / g ++ through the terminal. Take a search on the web.

If you tried and did not work, try setting the path variables again or:

Try reinstalling MinGW (C compiler).

During installation, see whether you can set the path variables automatically. After that restart the machine (as a precaution) and try again.

Whenever you want to see if the paths are working, call the program at a prompt.

    
11.03.2017 / 19:59