问题
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