7

I am learning to use CMake by the tutorial:http://derekmolloy.ie/hello-world-introductions-to-cmake/.I tried compiling my hello_world.cpp using cmake but i am getting this error message on MSys2 in Windows 10:

    -- The C compiler identification is unknown
    -- The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:3 (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.


  CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_CXX_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 "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 "D:/Hello_World/CMakeFiles/CMakeOutput.log".
  See also "D:/Hello_World/CMakeFiles/CMakeError.log".

This is my first post here.I am sorry for any mistake.

denisssj
  • 79
  • 5
  • `cl` is the Microsoft Visual Studio compiler. IIRC MSYS (and MSYS2) doesn't by default install MinGW (which is the compiler component of the package). Have you installed MinGW? From the MSYS shell, what happens if you run the program `gcc`? And from where are you running `cmake`? – Some programmer dude Mar 24 '20 at 07:09
  • Yes I have installed MinGW.I am running cmake in my folder D://Hello_world – denisssj Mar 24 '20 at 07:11
  • And if you type `gcc --version` in my Msys window -- do you get a proper gcc version output or error command not found? If it works, then you should have `gcc` as your compiler on line-3 and not `cl` (which is `cl.exe` the VS compiler). Now you can configure `cmake` to work with `cl.exe`, but that wouldn't be through Msys. – David C. Rankin Mar 24 '20 at 07:18
  • yes gcc version appears.Can I just not use my g++ compiler? – denisssj Mar 24 '20 at 07:24
  • Sure, I'm sorry, yes `g++` if you are building C++, `gcc` for C. My bad for not catching the [c++] tag. – David C. Rankin Mar 24 '20 at 07:29
  • What to do now @DavidC.Rankin – denisssj Mar 24 '20 at 07:35
  • Try to delete `CMakeCache.txt` from your build folder and run `cmake -G "MSYS Makefiles" .`, i.e. explicitly set the generator. – vre Mar 24 '20 at 07:37
  • Your error is `"CMake Error at CMakeLists.txt:3"`. So `cmake` is trying to use `cl` s the default compiler. You need to either change `CMakeLists.txt` to use `g++` or specify the `CC=gcc CXX=g++` on the command line before `cmake` (note you should remove any existing `build` directory that was created when `cmake` attempted to use `cl`). – David C. Rankin Mar 24 '20 at 07:40
  • Thanks it was able to detect the c compiler yet the compiler isnt able to run program i am getting error as:The C compiler "C:/msys64/mingw64/bin/gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: D:/Hello_World/CMakeFiles/CMakeTmp Run Build Command(s):nmake /nologo cmTC_e3962\fast && The system cannot find the file specified Generator: execution of make failed. Make command was: nmake /nologo cmTC_e3962\fast && – denisssj Mar 24 '20 at 08:28
  • `cmake` should be calling `make` with MinGW, not `nmake` (VS make). – David C. Rankin Mar 24 '20 at 18:18

0 Answers0