本文介绍了Windows中的cmake问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows中用cmake和MinGW编译这段代码(非常复杂的):

  #include< iostream> 

int main()
{
std :: cout<< 测试<<的std :: ENDL;
返回0;

这是 CMakeLists.txt
$ p code code code code $ $
$ (CMAKE_C_COMPILER path / to / gcc)
SET(CMAKE_CXX_COMPILER path / to / g ++)

project(cmake_test)

add_executable(a.exe test.cpp)

使用以下命令:

  cmake -GMinGW Makefiles。 

我得到这些错误:

<$ p $在C:/ Program Files(x86)/ CMake 2.8 / share / cmake-2.8 / Modules / CMakeMinGWFindMake.cmake:20(MESSAGE)中找到CMake错误:
sh.exe在你的路径,在这里:

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

为MinGW make正常工作sh.exe不能在你的路径中。

从PATH中没有sh.exe的shell运行cmake。

如果你想使用UNIX shell,那么使用MSYS Makefiles。

调用堆栈(最近调用优先):
CMakeLists.txt:8(项目)


CMake错误:错误需要内部CMake变量而不是设置,cmake可能无法正确构建。
缺少的变量是:
CMAKE_C_COMPILER_ENV_VAR
CMake的错误:无法找到cmake的模块文件:C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake
CMake的错误:错误所需的内部CMake的变量不设置,cmake可能无法正确构建。
缺少的变量是:
CMAKE_CXX_COMPILER_ENV_VAR
CMake的错误:无法找到cmake的模块文件:C:/cmake_test/CMakeFiles/CMakeCXXCompiler.cmake
- 配置不完整,出现的错误!

这些错误对我没有多大帮助。考虑到它在Linux中的作用,它必须与Window的配置有关。



感谢您的帮助!


- Windows 7

- MinGW / GCC 4.6.1

解决方案

这是由于你的路径 C:/MinGW/msys/1.0/bin/ ,用CMake和MinGW生成项目,将它从路径中删除并添加 C:/ MinGW / bin / ,而不是

I am trying to compile this (quite complex) piece of code with cmake and MinGW in Windows:

#include <iostream>

int main()
{
    std::cout << "Test" << std::endl;
    return 0;
}

This is the CMakeLists.txt file (which works correctly in 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)

With the command:

cmake -G"MinGW Makefiles" .

I get these errors:

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!

These errors did not help me much. Considering it works in Linux, it must be something related to the Window's configuration.

Thank you for any help!

Configuration:
- Windows 7
- MinGW/GCC 4.6.1

解决方案

This is due to you have in your path C:/MinGW/msys/1.0/bin/, for generating projects with CMake and MinGW, delete it from your path and add C:/MinGW/bin/ instead

这篇关于Windows中的cmake问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:30