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. Qt shared library project exporting symbols that arent marked for export?
Forum Updated to NodeBB v4.3 + New Features

Qt shared library project exporting symbols that arent marked for export?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 528 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.
  • osirisgothraO Offline
    osirisgothraO Offline
    osirisgothra
    wrote on last edited by
    #1

    Shared Library Project Exporting ALL Symbols

    I am unsure why this is happening, but I am assuming its some sort of automatic magic somewhere.

    Question

    What I'd like to know is this:

    • Does Qt further process symbols to decide automatically if they should be exported? (Like looking at relationships to other project)
    • Are there certain classes that always get exported in a Shared Lib Project (like QObject?)
    • Do the symbols for classes get exported if they are used by another class, when defined under the same library?
    • If the answer to any is yes, is there any setting to control this behavior?

    For simplicity i've omitted guards, access levels etc.. Let us assume these classes inherit from QObject in the usual manner...
    library.pro:

    ----file a.h---
    class EXPORTMACRO A() { A(); a(); }
    ----file a.cpp---
    #include "c.h"
    A::A() { yeah i should be able to run this, fine...}
    ----file b.h---
    class B() { B(); b(); }
    ----file b.cpp---
    #include "b.h"
    B::B() { For some reason, I can run this...but why? I'm not marked for export or import? }
    

    Its definitely using the library, if I take "mylib.so" away from the program's view, it will complain about missing the library when I try to run it, or complain about missing symbols if I try to recompile it in any form including just instancing the B() or just referencing the A() class.

    So the question becomes, why is this happening? Is there some way to control that?

    I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

    Pl45m4P 2 Replies Last reply
    0
    • osirisgothraO osirisgothra

      Shared Library Project Exporting ALL Symbols

      I am unsure why this is happening, but I am assuming its some sort of automatic magic somewhere.

      Question

      What I'd like to know is this:

      • Does Qt further process symbols to decide automatically if they should be exported? (Like looking at relationships to other project)
      • Are there certain classes that always get exported in a Shared Lib Project (like QObject?)
      • Do the symbols for classes get exported if they are used by another class, when defined under the same library?
      • If the answer to any is yes, is there any setting to control this behavior?

      For simplicity i've omitted guards, access levels etc.. Let us assume these classes inherit from QObject in the usual manner...
      library.pro:

      ----file a.h---
      class EXPORTMACRO A() { A(); a(); }
      ----file a.cpp---
      #include "c.h"
      A::A() { yeah i should be able to run this, fine...}
      ----file b.h---
      class B() { B(); b(); }
      ----file b.cpp---
      #include "b.h"
      B::B() { For some reason, I can run this...but why? I'm not marked for export or import? }
      

      Its definitely using the library, if I take "mylib.so" away from the program's view, it will complain about missing the library when I try to run it, or complain about missing symbols if I try to recompile it in any form including just instancing the B() or just referencing the A() class.

      So the question becomes, why is this happening? Is there some way to control that?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @osirisgothra

      Hi,

      read here:

      • https://doc.qt.io/qt-6/sharedlibrary.html#using-symbols-from-shared-libraries

      I think you forgot Q_DECL_IMPORT / Q_DECL_EXPORT


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      JonBJ 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @osirisgothra

        Hi,

        read here:

        • https://doc.qt.io/qt-6/sharedlibrary.html#using-symbols-from-shared-libraries

        I think you forgot Q_DECL_IMPORT / Q_DECL_EXPORT

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Pl45m4 said in Qt shared library project exporting symbols that arent marked for export?:

        I think you forgot Q_DECL_IMPORT / Q_DECL_EXPORT

        I think OP knows this. We are to assume EXPORTMACRO on class A has the necessary and correct Q_DECLs.

        class B does not have these. You then have to read the question in that light. It is a question of how B nonetheless seems as accessible as A.

        I think Q_DECL_IMPORT / Q_DECL_EXPORT is about import/export into/from a library, not to do with internal references.

        1 Reply Last reply
        0
        • osirisgothraO Offline
          osirisgothraO Offline
          osirisgothra
          wrote on last edited by
          #4

          so i think i got it now, turns out Linux shared libraries export all symbols by default, requiring attributes to HIDE the symbols, rather than on windows where symbols are NOT exported by default, that became evident when I looked up Q_DECL_EXPORT and Q_DECL_IMPORT's Linux-specific settings and saw they bear same attribute unlike windows which just translates them to __dllimport and __dllexport. Thanks for the input all the same :3

          I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

          1 Reply Last reply
          0
          • osirisgothraO osirisgothra

            Shared Library Project Exporting ALL Symbols

            I am unsure why this is happening, but I am assuming its some sort of automatic magic somewhere.

            Question

            What I'd like to know is this:

            • Does Qt further process symbols to decide automatically if they should be exported? (Like looking at relationships to other project)
            • Are there certain classes that always get exported in a Shared Lib Project (like QObject?)
            • Do the symbols for classes get exported if they are used by another class, when defined under the same library?
            • If the answer to any is yes, is there any setting to control this behavior?

            For simplicity i've omitted guards, access levels etc.. Let us assume these classes inherit from QObject in the usual manner...
            library.pro:

            ----file a.h---
            class EXPORTMACRO A() { A(); a(); }
            ----file a.cpp---
            #include "c.h"
            A::A() { yeah i should be able to run this, fine...}
            ----file b.h---
            class B() { B(); b(); }
            ----file b.cpp---
            #include "b.h"
            B::B() { For some reason, I can run this...but why? I'm not marked for export or import? }
            

            Its definitely using the library, if I take "mylib.so" away from the program's view, it will complain about missing the library when I try to run it, or complain about missing symbols if I try to recompile it in any form including just instancing the B() or just referencing the A() class.

            So the question becomes, why is this happening? Is there some way to control that?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @osirisgothra said in Qt shared library project exporting symbols that arent marked for export?:

            For some reason, I can run this...but why? I'm not marked for export or import?

            Where do you want to call B()? Within your library? Or from the program which where your lib is linked?

            Edit:

            Ok you figured it out already. :)


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • osirisgothraO Offline
              osirisgothraO Offline
              osirisgothra
              wrote on last edited by
              #6

              just as a follow up Q_DECL_HIDDEN was what you would use to force it to hidden in such cases
              Q_DECL_HIDDEN just does a attribute((visibility("hidden")))
              while Q_DECL_EXPORT/IMPORT both attribute((visibility("default"))) which is what tipped me off... On that hunch I searched and quickly found a general cross-platform discussion about Linux's exhibitionist nature vs Windows "more reserved" nature when it comes to shared libraries and that confirmed it :3 I wonder why since qt is cross platform that its not mentioned in the qt documentation's Shared library intro? (or least I didn't notice anything about it there).

              I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

              1 Reply Last reply
              0
              • osirisgothraO osirisgothra has marked this topic as solved on

              • Login

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