Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Shared Library
Forum Updated to NodeBB v4.3 + New Features

Shared Library

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 400 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ReneUafasahR Offline
    ReneUafasahR Offline
    ReneUafasah
    wrote on last edited by
    #1

    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-considerations

    I 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 ?

    1 Reply Last reply
    0
    • kkoehneK Offline
      kkoehneK Offline
      kkoehne
      Moderators
      wrote on last edited by
      #4

      @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.

      Director R&D, The Qt Company

      ReneUafasahR 1 Reply Last reply
      1
      • ReneUafasahR Offline
        ReneUafasahR Offline
        ReneUafasah
        wrote on last edited by
        #2

        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

        ReneUafasahR 1 Reply Last reply
        0
        • ReneUafasahR ReneUafasah

          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

          ReneUafasahR Offline
          ReneUafasahR Offline
          ReneUafasah
          wrote on last edited by
          #3

          @ReneUafasah

          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

          1 Reply Last reply
          0
          • kkoehneK Offline
            kkoehneK Offline
            kkoehne
            Moderators
            wrote on last edited by
            #4

            @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.

            Director R&D, The Qt Company

            ReneUafasahR 1 Reply Last reply
            1
            • kkoehneK kkoehne

              @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.

              ReneUafasahR Offline
              ReneUafasahR Offline
              ReneUafasah
              wrote on last edited by
              #5

              @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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved