Shared Library
-
Hello,
I am trying to apply the shared library method of compilation as recommended here
https://doc.qt.io/qt-5/sharedlibrary.html#header-file-considerationsI follow the script in an app:
set(sources MyClient.cpp MucosClient.cpp MyTopic.cpp ${PROJECT_SOURCE_DIR}/include/MyClient.h ${PROJECT_SOURCE_DIR}/include/MyTopic.h MucosClient.h ) add_definitions(-DMY_CLIENT_LIBRARY) set(linked_libraries PUBLIC Qt5::Core PUBLIC Qt5::Network PUBLIC ${mucos} PUBLIC my-api::utils PUBLIC my-api::persistence( sas_add_library(my-client SOURCES ${sources} DEPENDENCIES ${linked_libraries}) #pragma once #include <QtCore/QtGlobal> #if defined(MY_CLIENT_LIBRARY) # define MY_CLIENT_EXPORT Q_DECL_EXPORT #else # define MY_CLIENT_EXPORT Q_DECL_IMPORT #endif
Despite the fact that I have properly prefixed the class in MucosClient.cpp
class MY_CLIENT_EXPORT MuscosClient final : public QObject { Q_OBJECT public:
Linker errors (filtered, 1of 32):
MucosClient.obj:-1: error: LNK2019: unresolved external symbol __imp_mucos_lib_init referenced in function "public: __cdecl mb::sas::sas_common::MucosClient::MucosClient(class QString const &,unsigned short,class QString const &,bool)" (??0MucosClient@sas_common@sas@mb@@QEAA@AEBVQString@@G0_N@Z) [C:\.....common\my-client\my-client.vcxproj]
The LNK2019 unresolved error as we now is associated with not finding the body implementation of the class elements.
Are there any zipped "Hello World" examples using the shared library that show it working ? -
@ReneUafasah said in Shared Library:
The LNK2019 unresolved error as we now is associated with not finding the body implementation of the class elements.
It rather looks like you are not linking the mucos library.
Your code snippet contains
${mucos}
Do you initialize the variable anywhere?
In general, there are different ways to let CMake link against a library, from find_package() calls (preferred) to hardcoding linker commands, like qmake does. See e.g. https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Find-Libraries for an overview.
-
I guess the answer lies in working through a CMakeLists.txt equivalent of the following tutorial:
https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
-
I guess the answer lies in working through a CMakeLists.txt equivalent of the following tutorial:
https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
How can these PRO file contents be written in CMakeLists.txt?
TEMPLATE = app
TARGET =
DEPENDPATH += . ../testLib
INCLUDEPATH += ../testLib
LIBS += -L../testLib/debug -ltestLib
#Input
SOURCES += main.cpp -
@ReneUafasah said in Shared Library:
The LNK2019 unresolved error as we now is associated with not finding the body implementation of the class elements.
It rather looks like you are not linking the mucos library.
Your code snippet contains
${mucos}
Do you initialize the variable anywhere?
In general, there are different ways to let CMake link against a library, from find_package() calls (preferred) to hardcoding linker commands, like qmake does. See e.g. https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Find-Libraries for an overview.
-
@ReneUafasah said in Shared Library:
The LNK2019 unresolved error as we now is associated with not finding the body implementation of the class elements.
It rather looks like you are not linking the mucos library.
Your code snippet contains
${mucos}
Do you initialize the variable anywhere?
In general, there are different ways to let CMake link against a library, from find_package() calls (preferred) to hardcoding linker commands, like qmake does. See e.g. https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Find-Libraries for an overview.
@kkoehne
Thanks a lot.
That was indeed the problem.The name was wrong.
Using debug messaging in the Cmake 3.23.0 GUI Console Window, highlighted this to me.