CMake add_library: error LNK2001: unresolved external symbol "struct QMetaObject const myClass::staticMetaObject"
-
wrote on 17 Jan 2019, 13:52 last edited by tracyma
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 )
-
Hi,
Based on the cmake-qt documentation, it seems you have to include the corresponding generated files at the bottom of your .cpp files.
-
wrote on 18 Jan 2019, 01:11 last edited by tracyma
have tried, do not work. : <
AnimationItem
is QQuickItem-derived , how to deal with custom item in dll ? should iqmlRegisterType
the item somewhere ? -
wrote on 18 Jan 2019, 08:46 last edited by
qt5_add_resources
is obsolete. if youset(CMAKE_AUTORCC ON)
just add your .qrc files as they were .cpp toadd_library
/add_executable
- moc needs the headers, make sure CMake can see them, usually you can use
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1/4