首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CMake错误: MinGW make要正确工作,sh.exe不能出现在您的路径中

CMake错误: MinGW make要正确工作,sh.exe不能出现在您的路径中
EN

Stack Overflow用户
提问于 2013-09-10 13:50:27
回答 3查看 6.1K关注 0票数 0

我正试图在MinGW下用Qt5和cmake构建一个"Hello“项目。

这是CMakeLists.txt文件(取自在线文档):

代码语言:javascript
复制
project(Qt5_cmake_test)

cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

# Find the QtWidgets library
find_package(Qt5Widgets)

# Add the source files from the current directory
aux_source_directory(. SRC_LIST)

# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})

# Use the Widgets module from Qt5
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)

源代码是在创建新项目(生成空窗口)时自动生成的代码。

使用:cmake -G "MinGW Makefiles" ..\Qt5_cmake_test从Windows命令提示符进行配置

我知道这些错误:

代码语言:javascript
复制
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:/Program Files (x86)/Git/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: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/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: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cma
ke
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

因此,它似乎无法找到编译器。有没有办法让cmake自己找到它,或者只给它一个CMAKE_PREFIX_PATH目录?

我必须手动指定makefile中的所有变量还是Windows中的环境变量?

我尝试使用标准Windows命令提示符和Qt提供的命令提示符,结果相同。可以从Windows命令提示符构建,还是应该在MinGW的shell中进行构建?

平台:

Qt 5.1

CMake 2.8.11.2

MinGW/GCC 4.8

Windows 7

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-09-10 15:18:21

此CMakeLists.txt文件正常工作:

代码语言:javascript
复制
project(Qt5_cmake_test)

cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)

# Add the source files from the current directory
aux_source_directory(. SRC_LIST)

# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})

# Use Qt5 modules
target_link_libraries(${PROJECT_NAME}
    Qt5::Widgets
    Qt5::WinMain)

这些变化是:

增加了find_package(Qt5Core REQUIRED)

Qt5::WinMain添加到target_link_libraries中。

票数 1
EN

Stack Overflow用户

发布于 2016-03-31 01:07:15

在运行PATH之前,将git路径从您的cmake中取出。

这样做的神奇之处在于:

代码语言:javascript
复制
set PATH=%PATH:C:/Program Files (x86)/Git/bin;=%
票数 2
EN

Stack Overflow用户

发布于 2013-09-10 15:29:08

在我对此的一些回答中,我已经描述过了。CMake不喜欢sh.exe。

代码语言:javascript
复制
sh.exe was found in your PATH, here:

  C:/Program Files (x86)/Git/bin/sh.exe

解决方案:很快重命名C:/Program Files (x86)/Git/bin/sh.exe

例如:

代码语言:javascript
复制
C:/Program Files (x86)/Git/bin/shxx.exe

但别忘了什么都建好了。重命名一次。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18720773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档