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. Static variable corruption on shared library loading

Static variable corruption on shared library loading

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.1k 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.
  • M Offline
    M Offline
    Memmo
    wrote on last edited by
    #1

    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
    0
    • H Offline
      H Offline
      hipersayan_x
      wrote on last edited by
      #2

      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
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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
        0

        • Login

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