windos 下 cmake msys2編譯器配置詳解

(1)問題1:cl is not a full path and was not found in the PATHshell

 cmake .ide

-- Building for: NMake Makefilesui

-- The C compiler identification is unknownthis

-- The CXX compiler identification is unknownci

CMake Error at CMakeLists.txt:5 (project):get

  The CMAKE_C_COMPILER:generator

 

    clit

 

  is not a full path and was not found in the PATH.io

 

  To use the NMake generator with Visual C++, cmake must be run from a shelltable

  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:5 (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.

 

解決方法:注意gcc.exe必定要帶上exe文件名!

export CC="/d/msys64/mingw64/bin/gcc.exe"       

export CXX="/d/msys64/mingw64/bin/g++.exe"

cmake /path/to/your/project

 

(2)問題2

$ cmake .

-- Building for: NMake Makefiles

-- The C compiler identification is GNU 5.3.0

-- The CXX compiler identification is GNU 5.3.0

-- Check for working C compiler: D:/msys32/mingw32/bin/gcc.exe

CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_409d1\fast"

-- Check for working C compiler: D:/msys32/mingw32/bin/gcc.exe -- broken

CMake Error at D:/msys32/mingw32/share/cmake-3.4/Modules/CMakeTestCCompiler.cmake:61 (message):

  The C compiler "D:/msys32/mingw32/bin/gcc.exe" is not able to compile a

  simple test program.

  It fails with the following output:

   Change Dir: D:/msys32/home/Demo1/CMakeFiles/CMakeTmp

  Run Build Command:"nmake" "/NOLOGO" "cmTC_409d1\fast"

  系統找不到指定的文件。

  Generator: execution of make failed.  Make command was: "nmake" "/NOLOGO"

  "cmTC_409d1\fast"

解決方法:

cmake . -G"MSYS Makefiles"

 

(3) 運行結果

$ cmake . -G"MSYS Makefiles"

-- The C compiler identification is GNU 5.3.0

-- The CXX compiler identification is GNU 5.3.0

-- Check for working C compiler: D:/msys32/mingw32/bin/gcc.exe

-- Check for working C compiler: D:/msys32/mingw32/bin/gcc.exe -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Detecting C compile features

-- Detecting C compile features - done

-- Check for working CXX compiler: D:/msys32/mingw32/bin/g++.exe

-- Check for working CXX compiler: D:/msys32/mingw32/bin/g++.exe -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Detecting CXX compile features

-- Detecting CXX compile features - done

-- Configuring done

-- Generating done

-- Build files have been written to: D:/msys32/home/Demo2

$ make

Scanning dependencies of target Demo

[ 33%] Building CXX object CMakeFiles/Demo.dir/main.cc.obj

[ 66%] Building CXX object CMakeFiles/Demo.dir/MathFunctions.cc.obj

[100%] Linking CXX executable Demo.exe

[100%] Built target Demo

$ ./demo 3 3

3 ^ 3 is 27

阿英講Cmake msys32使用問題解答 CXX CMAKE_C_COMPILER配置詳解 - 阿英 - Mr.Right

相關文章
相關標籤/搜索