windos 下 cmake msys2编译器配置详解

(1)问题1:cl is not a full path and was not found in the PATH

 cmake .

-- Building for: NMake Makefiles

-- The C compiler identification is unknown

-- The CXX compiler identification is unknown

CMake Error at CMakeLists.txt:5 (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: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/msys32/mingw32/bin/gcc.exe"       

export CXX="/d/msys32/mingw32/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

windos 下 cmake msys2编译器配置详解

windos 下 cmake msys2编译器配置详解

上一篇:Windows下Composer安装PsySH


下一篇:c# web文件上传时文件过大404错误的问题