Windows中的cmake问题

Pie*_*tro 9 windows configuration gcc cmake

我试图用Windows中的cmake和MinGW 编译这个(相当复杂的)代码片段:

#include <iostream>

int main()
{
    std::cout << "Test" << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是CMakeLists.txt文件(在Linux中正常工作):

cmake_minimum_required(VERSION 2.6)

SET(CMAKE_C_COMPILER path/to/gcc)
SET(CMAKE_CXX_COMPILER path/to/g++)

project(cmake_test)

add_executable(a.exe test.cpp)
Run Code Online (Sandbox Code Playgroud)

使用命令:

cmake -G"MinGW Makefiles" .
Run Code Online (Sandbox Code Playgroud)

我收到这些错误:

CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (MESSAGE):
  sh.exe was found in your PATH, here:

  C:/MinGW/msys/1.0/bin/sh.exe

  For MinGW make to work correctly sh.exe must NOT be in your path.

  Run cmake from a shell that does not have sh.exe in your PATH.

  If you want to use a UNIX shell, then use MSYS Makefiles.

Call Stack (most recent call first):
  CMakeLists.txt:8 (project)


CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/cmake_test/CMakeFiles/CMakeCXXCompiler.cmake
-- Configuring incomplete, errors occurred!
Run Code Online (Sandbox Code Playgroud)

这些错误对我没什么帮助.考虑到它在Linux中有效,它必须与Window的配置相关.

感谢您的任何帮助!

配置:
- Windows 7
- MinGW/GCC 4.6.1

And*_*jos 5

你可能会有更好的结果-G "MSYS Makefiles"而不是"MinGW Makefiles"- 但我警告你 - 它会变慢.


fen*_*688 3

这是因为您的路径中有 C:/MinGW/msys/1.0/bin/,要使用 CMake 和 MinGW 生成项目,请将其从路径中删除并C:/MinGW/bin/添加