赞
踩
Only God knows how much time ive wasted on dealing it!!!
vs自动生成的cmakelists somehow在我的电脑上跑不成功, 无穷的debug之后发现, bug is:
你需要把vs自动生成的这段cmakelists ↓
target_link_libraries(QtLearning1
PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
)
改为
target_link_libraries(QtLearning1
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
)
或者
target_link_libraries(QtLearning1
PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
)
同时 为了解决windows平台下dll复制的问题,即:
需要在cmakelists最后添加这段话:
if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(DEBUG_SUFFIX) if (MSVC AND 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}>/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}>/platforms/") endif () foreach (QT_LIB Core Gui Widgets) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll" "$<TARGET_FILE_DIR:${PROJECT_NAME}>") endforeach (QT_LIB) endif ()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。