2012-10-24 52 views
9

我想編譯這個(相當複雜)一塊與cmake並MinGW的代碼在Windows中:cmake的問題

#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

+2

從C進行錯誤信息是明確的:確保你沒有在你的道路上。即:不要從MSys提示符運行CMake -G「MinGW Makefiles」。 –

+0

那麼爲什麼在我的路徑中有sh.exe是一個問題? – odiszapc

+0

通過運行'where sh.exe'我在'C:\ Cygwin64 \ bin \ sh.exe'和'C:\ Program Files \ OpenSSH'bin'sh.exe'找到它。我應該如何移除'Cygwin'和'OpenSSH'主文件夾而不破壞它們? – hyprfrcb

回答

3

這是因爲你必須在你的路徑C:/MinGW/msys/1.0/bin/,用於生成與CMake和MinGW的項目,從您的路徑中刪除,並添加C:/MinGW/bin/代替

+0

'C:\ ProgramData \ chocolatey \ lib \ msys2'怎麼辦?這完全不相關? – hyprfrcb

2

刪除從PATH改善的事情sh.exe。
我得到更多的錯誤,但在以後的階段......

5

你可能有-G "MSYS Makefiles",而不是"MinGW Makefiles"更好的結果 - 但我提醒你 - it is going to be slow