Qt Forum

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

    Static variable corruption on shared library loading

    General and Desktop
    3
    3
    985
    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.
    • M
      Memmo last edited by

      Could anyone explain why loading shared library corrupts static variable?

      • Output on Linux (AltLinux, openSUSE): 1 true 0
        
      • Output on Windows (using MinGW): 1 true 1

      Qt 5.3.1: https://github.com/ipostanogov/variables-destroyer

      // Not satisfied with answers @ http://stackoverflow.com/q/26317163

      1 Reply Last reply Reply Quote 0
      • H
        hipersayan_x last edited by

        I've tested your example in Arch Linux (gcc 4.9.1 and clang 3.5.0, Qt 4.8.6 and 5.3.2) and it give me 1 true 1 that seems to be the right solution. Its maybe a bug of your compiler, it could be also that when you load the plugin you are redefining the Core::list variable in "this line":https://github.com/ipostanogov/variables-destroyer/blob/master/core/core.cpp#L3.

        1 Reply Last reply Reply Quote 0
        • G
          giesbert last edited by

          global variables (which you use there) are accessed by names and all names are exported on Linux. This implies that each global name MUST exist only once. E.g. havin a shared library with a global variable
          @
          int myVal;
          @

          and another library with
          @
          QString myVal;
          @

          it is undefined which one exists in the process memory. It can be any of these but only one. On Windows, the behavior is different, as only exported names are globally.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post