Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    6
    406
    Loading More Posts
    • 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.
    • btse
      btse last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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

        btse 1 Reply Last reply Reply Quote 0
        • btse
          btse @SGaist last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • btse
              btse last edited by

              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 Reply Quote 0
              • btse
                btse last edited by

                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 Reply Quote 0
                • First post
                  Last post