cmake ปัญหาใน Windows

ฉันกำลังพยายามรวบรวมโค้ด (ค่อนข้างซับซ้อน) นี้ด้วย cmake และ MinGW ใน Windows:

#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

ขอบคุณสำหรับความช่วยเหลือ!

การกำหนดค่า:
- Windows 7
- MinGW/GCC 4.6.1


person Pietro    schedule 24.10.2012    source แหล่งที่มา
comment
ข้อความแสดงข้อผิดพลาดจาก CMake นั้นชัดเจน: ตรวจสอบให้แน่ใจว่าคุณไม่มี sh ในเส้นทางของคุณ นั่นคือ: อย่าเรียกใช้ CMake -GMinGW Makefiles จากพรอมต์ MSys ของคุณ   -  person André    schedule 21.01.2015
comment
เหตุใดการมี sh.exe ในเส้นทางของฉันจึงเป็นปัญหา   -  person odiszapc    schedule 31.05.2017
comment
เมื่อเรียกใช้ where sh.exe ฉันพบมันที่ C:\Cygwin64\bin\sh.exe และ C:\Program Files\OpenSSHbinsh.exe ฉันจะลบโฟลเดอร์หลัก Cygwin และ OpenSSH โดยไม่ทำลายได้อย่างไร   -  person Brethlosze    schedule 04.10.2017


คำตอบ (3)


นี่เป็นเพราะคุณมีเส้นทาง C:/MinGW/msys/1.0/bin/ ในการสร้างโครงการด้วย CMake และ MinGW ให้ลบออกจากเส้นทางของคุณและเพิ่ม C:/MinGW/bin/ แทน

person fenix688    schedule 22.01.2015
comment
แล้วC:\ProgramData\chocolatey\lib\msys2ล่ะ สิ่งนี้ไม่เกี่ยวข้องกันโดยสิ้นเชิงใช่ไหม? - person Brethlosze; 04.10.2017

คุณอาจได้ผลลัพธ์ที่ดีกว่าด้วย -G "MSYS Makefiles" แทนที่จะเป็น "MinGW Makefiles" - แต่ฉันเตือนคุณ - มันคือ จะช้า.

person André Anjos    schedule 16.08.2013

การลบ sh.exe ออกจาก PATH สิ่งที่ปรับปรุงแล้ว
ฉันได้รับข้อผิดพลาดเพิ่มเติม แต่ในภายหลัง...

person Pietro    schedule 24.10.2012