gpt4 book ai didi

qt4 - 如何在 CMake 中正确链接到 QT4 库?

转载 作者:行者123 更新时间:2023-12-04 20:11:07 25 4
gpt4 key购买 nike

所以我试图构建一个最初用 制作的程序CMake 而不是 .pro 文件。但是,我无法构建它,因为库声明有问题。例如,以下将不起作用:

#include <QtGui/QApplication>

但是,这或多或少有效,但不完全:
#include <qt4/QtGui/QApplication>

如果我使用上述内容,那么我会收到大量错误,因为编译器说它找不到其他 header 指向的 header 。问题是前缀 qt4 .
如何在 CMake 文件中正确链接它,以便可以在 qt4 下找到每个 header ,而无需更改 QT-SDK 附带的整个 header ?

CMAKE 文件:(来源: http://code.metager.de/source/xref/kde/Support/polkit-qt-1/examples/CMakeLists.txt)
install(FILES org.qt.policykit.examples.policy DESTINATION ${SHARE_INSTALL_PREFIX}/polkit-1/actions/)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/gui
)

set(polkit_example_SRCS
main.cpp
PkExample.cpp
)

SET(polkit_example_RESOUCES
icons/icons.qrc
)

FIND_PACKAGE(Qt4 REQUIRED)

QT4_WRAP_CPP(polkit_example_MOC_SRCS
PkExample.h
)

QT4_WRAP_UI(polkit_example_UI_SRCS
PkExample.ui
)

QT4_ADD_RESOURCES (qtsourceview_RC_SRCS ${polkit_example_RESOUCES})

add_executable(polkit-example
${polkit_example_SRCS}
${polkit_example_MOC_SRCS}
${polkit_example_UI_SRCS}
${qtsourceview_RC_SRCS}
)

target_link_libraries(polkit-example
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
polkit-qt-gui-1
polkit-qt-core-1
)

#--------Helper Application

# This macro is defined in FindPolkitQt.cmake
macro(dbus_add_activation_system_service _sources)
foreach (_i ${_sources})
get_filename_component(_service_file ${_i} ABSOLUTE)
string(REGEX REPLACE "\\.service.*$" ".service" _output_file ${_i})
set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_output_file})
configure_file(${_service_file} ${_target})
install(FILES ${_target} DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/system-services )
#install(FILES ${_target} DESTINATION ${_install_dir})
endforeach (_i ${ARGN})
endmacro(dbus_add_activation_system_service _sources)

set(polkit_example_helper_SRCS
PkExampleHelper.cpp
mainHelper.cpp
)

qt4_add_dbus_adaptor(polkit_example_helper_SRCS
org.qt.policykit.examples.xml
PkExampleHelper.h
PkExampleHelper
)

QT4_WRAP_CPP(polkit_example_helper_MOC_SRCS
PkExampleHelper.h
)

add_executable(polkit-example-helper
${polkit_example_helper_SRCS}
${polkit_example_helper_MOC_SRCS}
)

# see our helper is pretty small :D
target_link_libraries(polkit-example-helper
${QT_QTCORE_LIBRARY}
polkit-qt-core-1
)


dbus_add_activation_system_service(org.qt.policykit.examples.service.in)

install(FILES org.qt.policykit.examples.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d)

最佳答案

据我所知,你很接近。在您的 FIND_PACKAGE(Qt4 REQUIRED) 之后包括以下行:

INCLUDE(${QT_USE_FILE})



根据 the documentation

The file pointed to by QT_USE_FILE will set up your compile environment by adding include directories, preprocessor defines, and populate a QT_LIBRARIES variable containing all the Qt libraries and their dependencies.



所以这应该为你设置正确的路径。

关于qt4 - 如何在 CMake 中正确链接到 QT4 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16123817/

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