【问题标题】:cmake problems in WindowsWindows中的cmake问题
【发布时间】:2012-10-14 09:40:42
【问题描述】:

我正在尝试在 Windows 中使用 cmake 和 MinGW 编译这段(相当复杂)代码:

#include <iostream>

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

这是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)

使用命令:

cmake -G"MinGW Makefiles" .

我收到以下错误:

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!

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

感谢您的帮助!

配置:
- 视窗 7
- MinGW/GCC 4.6.1

【问题讨论】:

  • CMake 的错误信息很明确:确保路径中没有 sh。即:不要在 MSys 提示符下运行 CMake -G"MinGW Makefiles"。
  • 那么为什么在我的路径中有 sh.exe 是个问题?
  • 通过运行where sh.exe,我在C:\Cygwin64\bin\sh.exeC:\Program Files\OpenSSHbinsh.exe 找到了它。我应该如何删除 CygwinOpenSSH 主文件夹而不破坏它们?

标签: windows gcc configuration cmake


【解决方案1】:

使用-G "MSYS Makefiles" 而不是"MinGW Makefiles" 可能会有更好的结果 - 但我警告你 - it is going to be slow

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • C:\ProgramData\chocolatey\lib\msys2 怎么样。这完全不相关吗?
    【解决方案3】:

    从 PATH 中删除 sh.exe 得到改进。
    我收到更多错误,但在稍后阶段...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多