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. Using a static lib's static variable inside of a plugin

Using a static lib's static variable inside of a plugin

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 675 Views
  • 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.
  • btseB Offline
    btseB Offline
    btse
    wrote on last edited by
    #1

    So we have our own custom logging mechanism. This mechanism is accessed through a static member variable of the logging class. The logger is compiled as part of a static lib.

    We are also moving towards a plugin architecture and would like to make use of the logger inside of the plugins. However, accessing the logger's static member variable returns a null ptr from within the plugin code. Accessing the logger from any app or static lib code works as expected.

    I'm guessing this has to do with how plugins are loaded and the fact that they don't immediately share the same memory space as the app.

    Is there a way to achieve my goal or do we have to redesign how our logger works?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are your plugins built against your static library ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      btseB 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Are your plugins built against your static library ?

        btseB Offline
        btseB Offline
        btse
        wrote on last edited by
        #3

        @SGaist As in, am I statically compiling the static libs into the plugin? I do not believe I am. Also, the plugins are not being statically compiled into my app but loaded at run-time.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What I meant is literally what I wrote: are your plugins linked against that static library ? There's no concept of "shared linking against a static library".

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • btseB Offline
            btseB Offline
            btse
            wrote on last edited by
            #5

            Forgive my ignorance. In my plugin's project file, I have defined

            LIBS += -llib1 -llib2...
            DEPENDPATH += lib1 lib2..
            PRE_TARGETDEPS += lib1.a lib2.a...
            

            So I think so? My plugins build completely, so I'm guessing all symbols are resolved correctly.

            Let me know if you need more info

            1 Reply Last reply
            0
            • btseB Offline
              btseB Offline
              btse
              wrote on last edited by
              #6

              So I was able to fix this myself by wrapping access to the class's static variable with a static function.

              I have a feeling my usage of macros was causing part of the problem. Some of the macros were using the static member variable, and perhaps this was causing a separate translation unit in the plugin? I still don't quite understand what was happening underneath. Any explanation will be greatly appreciated.

              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