CMake错误:要使MinGW make正常工作,sh.exe不能位于您的路径中

ztigrdn8  于 2022-11-11  发布在  其他
关注(0)|答案(3)|浏览(251)

我正在尝试用Qt 5和MinGW下的cmake构建一个“Hello World”项目。
这是CMakeLists.txt文件(取自在线文档):

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)

源代码是在创建新项目时自动生成的代码(这会生成一个空窗口)。
使用以下命令从Windows命令提示符进行配置:cmake -G "MinGW Makefiles" ..\Qt5_cmake_test
我得到这些错误:

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下构建?
操作平台:
第5.1季度
CMake 2.8.11.2
最小GW/GCC 4.8
视窗7

yeotifhr

yeotifhr1#

在运行cmake之前,从PATH中获取git路径。
下面是实现这一点的魔法:

set PATH=%PATH:C:/Program Files (x86)/Git/bin;=%
6qfn3psc

6qfn3psc2#

此CMakeLists.txt文件工作正常:

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

vwoqyblh

vwoqyblh3#

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

sh.exe was found in your PATH, here:

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

解决方案:稍后重命名C:/Program Files (x86)/Git/bin/sh.exe
例如:

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

但不要忘记当一切都建立。重新命名正确。

相关问题