forced to use QT5_WRAP_CPP macro instead of automoc property in cmake

拜拜、爱过 提交于 2019-12-11 09:52:39

问题


According to the cmake documentation I should be able to only use a property rather than having to wrap my header files, which contain a Q_OBJECT macro like in the following cmake snippet. If I use the wrapping macro the code compiles and runs but if I use only the enabled property, I get a compiler error

../gui/libgui.so: undefined reference to `vtable for ImageWidget'

why is that?

cmake_minimum_required (VERSION 3.5.1 FATAL_ERROR)
project (app)

#QT5_WRAP_CPP(MOC_files
#       ../gui/include/gui/imageWidget.hpp
#)

add_executable(${PROJECT_NAME}
    main.cpp
    #  ${MOC_files}
)

target_include_directories(${PROJECT_NAME}
    PUBLIC ${PROJECT_BINARY_DIR}
)

set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC TRUE)

target_link_libraries(${PROJECT_NAME}
     PRIVATE
    Qt5::Widgets
    Qt5::Core
    Qt5::Xml
    Qt5::OpenGL
    Qt5::Gui
)

set_target_properties(${PROJECT_NAME} PROPERTIES 
    INSTALL_RPATH "$ORIGIN:${CMAKE_INSTALL_PREFIX}/lib:$ORIGIN/")

install(TARGETS ${PROJECT_NAME}
        DESTINATION bin)

来源:https://stackoverflow.com/questions/49027620/forced-to-use-qt5-wrap-cpp-macro-instead-of-automoc-property-in-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!