CMake add_library: error LNK2001: unresolved external symbol "struct QMetaObject const myClass::staticMetaObject"
Unsolved
General and Desktop
-
Get link error when build dll library:
1>animationitem.obj : error LNK2001: unresolved external symbol "struct QMetaObject const myclass::staticMetaObject" (?staticMetaObject@myclass@@3UQMetaObject@@B)
.moc_animationitem.cpp
is actually generated. I have no idea what's wrong.VS project is generated from CMake.
Qt 5.12.0
VS 2017 x86cmake_minimum_required(VERSION 3.10.0) project(libMyClass) add_subdirectory( 7zip ) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) find_package(Qt5 COMPONENTS Core Gui Widgets Quick Qml QuickControls2 WebEngineWidgets WebView WebChannel Svg Xml Multimedia REQUIRED) qt5_add_resources( QT_RESOURCES resource.qrc ) add_library( libMyClass SHARED # and others ... items/animationitem.cpp ) target_compile_definitions( libMyClass PRIVATE ITEM_MODE_VIEW BUILD_XESLIDE_DLL ) #target_compile_options( libMyClass PRIVATE -Wall ) target_compile_features( libMyClass PRIVATE cxx_std_17 ) target_include_directories( libMyClass PRIVATE . 7zip/win/CPP 7zip/win/C player/player_widgets UI ) target_link_libraries( libMyClass PUBLIC Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Quick Qt5::Qml Qt5::QuickControls2 Qt5::WebEngineWidgets Qt5::WebView Qt5::WebChannel Qt5::Svg Qt5::Xml Qt5::Multimedia libArchive user32.lib )