Not able to compile project by cmake on MSys2
Asked Answered
K

0

8

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.

Kindig answered 24/3, 2020 at 7:4 Comment(10)
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?Stockbroker
Yes I have installed MinGW.I am running cmake in my folder D://Hello_worldKindig
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.Kabuki
yes gcc version appears.Can I just not use my g++ compiler?Kindig
Sure, I'm sorry, yes g++ if you are building C++, gcc for C. My bad for not catching the [c++] tag.Kabuki
What to do now @DavidC.RankinKindig
Try to delete CMakeCache.txt from your build folder and run cmake -G "MSYS Makefiles" ., i.e. explicitly set the generator.Devolve
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).Kabuki
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 &&Kindig
cmake should be calling make with MinGW, not nmake (VS make).Kabuki

© 2022 - 2024 — McMap. All rights reserved.