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. Trouble with shared object
Forum Updated to NodeBB v4.3 + New Features

Trouble with shared object

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 5.2k 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.
  • D Offline
    D Offline
    dorik
    wrote on last edited by
    #3

    I think it is. A moc object is definitely being created. Another thing to note is that I can get it to work if I include the base class definition in the shared library. But, I don't think I should have to do this.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #4

      Did I understand correct:

      you have an executable (the app) that vtries to export classes, that should be used by other binaries (exes, dynamic libraries)?

      That is not possible!

      You can export stuff from dynamic libraries and use them in executables, but not the other way round.

      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
      • D Offline
        D Offline
        dorik
        wrote on last edited by
        #5

        That's what I originally thought. But apparently, a shared library can have unresolved symbols that the application can fill in. You can check here: "http://www.informit.com/articles/article.aspx?p=22435&rll=1":http://www.informit.com/articles/article.aspx?p=22435&rll=1

        I've made a simple example program before where the shared object contains a subclass of an object in the main app. The shared object does not contain the parent class's definition (only the header), but is resolved when loaded into the main app.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #6

          Ok, perhaps that works on Linux, but it does definitely not work on windows.

          But you would go the safe way, if you put the base class to a dll.

          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
          • D Offline
            D Offline
            dorik
            wrote on last edited by
            #7

            That is an option. I could try putting the base class in it's own shared object. But, the base class has a static member. If it's linked in to the main application and the shared object, will there be two copies of of the member?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #8

              please define shared object...

              If you mean a dll, then the answer is definitely no, as the dll is only loaded once. IUt doesn't matter if it's a windows dll or a Linux shared library (.so).

              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
              • D Offline
                D Offline
                dorik
                wrote on last edited by
                #9

                Oh right, I guess that's what shared objects are for! What if the base class was not put into its own shared library, but the definition cpp was put in both the shared library and the main app. Would that cause two static members?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #10

                  YES.

                  That would create double defined methods and not really 2 static members. On windows, it would have 2 members, on linux only one. The last one wins. If one is of type int and one of type string, the last loaded one is the existing one. Same appears to initialization.

                  If the member is called static ... inside the cpp file, then it will appear twice, it it's a static member in the class, it will appear once on Linux, twice on windows.

                  But definitely not what you expect :-(

                  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
                  • D Offline
                    D Offline
                    dorik
                    wrote on last edited by
                    #11

                    I see, thanks for clearing that up!

                    I would still really like to get it working where the shared object only has the subclass definition. The idea is that there will be many shared objects to work like plugins. They return a pointer to the base class and the main app uses it through polymorphism. I know this is possible but something just isn't working with Qt. I'm quite sure it has to do with moc objects. From what I can see, the base class moc is compiled in with the main app and the subclass moc is compiled into the .so. Why are there undefined symbols?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dorik
                      wrote on last edited by
                      #12

                      Interesting. After compiling the project with and without Wl,--export-dynamic, I checked the output of nm on the executable. I used nm -D to show the dynamic symbols and the output was the same in both cases. So does this mean Wl,--export-dynamic is not doing anything?

                      I've been including it under QMAKE_CXXFLAGS in my .pro file.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dorik
                        wrote on last edited by
                        #13

                        I found the problem!! :)

                        So, Qt was including -Wl,--export-dynamic when it compiled each c++ file, but not in the final link. I added it in manually and things seem to work as I had hoped.

                        Is there another variable I can use in the .pro file?

                        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