gpt4 book ai didi

Qt。尝试运行项目时复制文件错误。如何纠正错误以及为什么会发生错误?

转载 作者:行者123 更新时间:2023-12-05 02:01:19 33 4
gpt4 key购买 nike

我正在尝试安装和创建第一个 Qt 项目。我将 CLion 与 CMake 和 Qt 6 一起使用。我设置了 CMake:

cmake_minimum_required(VERSION 3.17)
project(QSnake)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(QT_VERSION 6)
set(REQUIRED_LIBS Core Gui Widgets)
set(REQUIRED_LIBS_QUALIFIED Qt6::Core Qt6::Gui Qt6::Widgets)

set(CMAKE_PREFIX_PATH D:/Qt/6.0.2/mingw81_64/lib/cmake)

add_executable(${PROJECT_NAME} main.cpp)

if(NOT CMAKE_PREFIX_PATH)
message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
"(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif()
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
if(WIN32)
set(DEBUG_SUFFIX)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_SUFFIX "d")
endif()
set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
if(NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
if(NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
endif()
endif()
if(EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
endif()
foreach(QT_LIB ${REQUIRED_LIBS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
endforeach(QT_LIB)
endif()

其实在创建CLion工程的时候就是这样生成的。我只设置了路径:D:/Qt/6.0.2/mingw81_64/lib/cmake

为了以防万一,我也会添加 main.c 代码。它也是由 CLion 生成的。

#include <QApplication>
#include <QPushButton>

int
main(int argc,
char *argv[])
{
QApplication a(argc, argv);
QPushButton button("Hello world!", nullptr);
button.resize(200, 100);
button.show();
return QApplication::exec();
}

我没有发现 CMake 有任何问题,但是当我尝试运行该项目时出现错误:

Error copying file "D:/Qt/6.0.2/mingw81_64/lib/cmake/../../bin/Qt6Cored.dll" to "D:/QSnake/cmake-build-debug".
mingw32-make[3]: *** [CMakeFiles\QSnake.dir\build.make:126: QSnake.exe] Error 1
mingw32-make[3]: *** Deleting file 'QSnake.exe'
mingw32-make[2]: *** [CMakeFiles\Makefile2:96: CMakeFiles/QSnake.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:103: CMakeFiles/QSnake.dir/rule] Error 2
mingw32-make: *** [Makefile:137: QSnake] Error 2

这是什么错误,我该如何解决?我知道构建没有问题 - 只是复制错误。复制的 dll 应该称为“Cored”而不是“Core”吗?

感谢您的关注!如果您需要任何其他信息,请告诉我 - 我会尽力澄清这个问题。

最佳答案

问题解决了。是否对任何人都有用,但CLion自动生成的CMake包含在 Debug模式下导致错误的行(为所有dll文件添加'd'后缀):

if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_SUFFIX "d")
endif()

删除那些行救了我 :)

关于Qt。尝试运行项目时复制文件错误。如何纠正错误以及为什么会发生错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66675088/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com