Error when compiling Cmake project

Asked

Viewed 268 times

1

I have 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 environment variables CMAKE_C_COMPILER and CMAKE_CX_COMPILER 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 remained.

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 overlooked some basic step. Does anyone have any idea what might be causing the problem?

2 answers

2


I found out what I was doing wrong. I’m not sure, though, why it wasn’t 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.

0

Looks like he’s not finding the C Compiler in his system. It may be that your path variables are not correct.

To check if the variables were set correctly, open your command prompt and call the compiler from C. I don’t remember what the command is to call gcc/g++ from the terminal. Take a web search.

If you tried and it didn’t work, try setting the path variables again or:

Try to reinstall Mingw (C compiler).

During the installation, see if there is an option to set the path variables automatically. After that restart the machine(for precaution) and try again.

Whenever you want to see if the paths variables are working, call the program by prompt.

  • This was not the problem. The compiler was ok. The answer below explains what was happening.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.