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. How to compile a so file in order to load it as a library.

How to compile a so file in order to load it as a library.

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 3 Posters 10.3k 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.
  • jsulmJ jsulm

    @jenya7 said in How to compile a so file in order to load it as a library.:

    and it's a shortcut file which I can not open

    Why do you want to open it?
    Did you try:

    g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
    

    ?
    Are you on ARM platform or are you doing cross compilation?

    J Offline
    J Offline
    jenya7
    wrote on last edited by
    #15

    @jsulm said in How to compile a so file in order to load it as a library.:

    @jenya7 said in How to compile a so file in order to load it as a library.:

    and it's a shortcut file which I can not open

    Why do you want to open it?
    Did you try:

    g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
    

    ?
    Are you on ARM platform or are you doing cross compilation?

    It's Raspberry Pi - Debian. Qt installed on board and I build directly on board.

    jsulmJ 1 Reply Last reply
    0
    • J jenya7

      @jsulm said in How to compile a so file in order to load it as a library.:

      @jenya7 said in How to compile a so file in order to load it as a library.:

      and it's a shortcut file which I can not open

      Why do you want to open it?
      Did you try:

      g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
      

      ?
      Are you on ARM platform or are you doing cross compilation?

      It's Raspberry Pi - Debian. Qt installed on board and I build directly on board.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #16

      @jenya7 Then -lQt5Core should be enough, no need for -L

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      0
      • jsulmJ jsulm

        @jenya7 Then -lQt5Core should be enough, no need for -L

        J Offline
        J Offline
        jenya7
        wrote on last edited by
        #17

        @jsulm said in How to compile a so file in order to load it as a library.:

        @jenya7 Then -lQt5Core should be enough, no need for -L

        Thank you.
        g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
        It works. Now it's quit a nightmare - it's like a chain reaction - demands more and more dependencies. I include each time, hope it'll come till the end eventually. My command line string takes the full screen already.

        jsulmJ 1 Reply Last reply
        0
        • J jenya7

          @jsulm said in How to compile a so file in order to load it as a library.:

          @jenya7 Then -lQt5Core should be enough, no need for -L

          Thank you.
          g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
          It works. Now it's quit a nightmare - it's like a chain reaction - demands more and more dependencies. I include each time, hope it'll come till the end eventually. My command line string takes the full screen already.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #18

          @jenya7 You should use a proper build system like QMake or CMake instead of hacking around with all these manually...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          J 1 Reply Last reply
          0
          • jsulmJ jsulm

            @jenya7 You should use a proper build system like QMake or CMake instead of hacking around with all these manually...

            J Offline
            J Offline
            jenya7
            wrote on last edited by
            #19

            @jsulm
            One dependence I can't resolve - undefined symbol: _ZN7QAction16staticMetaObjectE
            Where could it be - QAction - is it a separate library?

            jsulmJ 1 Reply Last reply
            0
            • J jenya7

              @jsulm
              One dependence I can't resolve - undefined symbol: _ZN7QAction16staticMetaObjectE
              Where could it be - QAction - is it a separate library?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #20

              @jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J 1 Reply Last reply
              1
              • jsulmJ jsulm

                @jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)

                J Offline
                J Offline
                jenya7
                wrote on last edited by
                #21

                @jsulm said in How to compile a so file in order to load it as a library.:

                @jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)

                sorry to bother but I included
                -L/usr/lib/arm-linux-gnueabihf/ -lQt5Gui
                and QAction is good now but I get
                undefined symbol: _ZN12QActionGroup16staticMetaObjectE
                but I see QAction and QActionGroup in the same library (QT += gui)
                Do I miss some lib?

                JonBJ jsulmJ 2 Replies Last reply
                0
                • J jenya7

                  @jsulm said in How to compile a so file in order to load it as a library.:

                  @jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)

                  sorry to bother but I included
                  -L/usr/lib/arm-linux-gnueabihf/ -lQt5Gui
                  and QAction is good now but I get
                  undefined symbol: _ZN12QActionGroup16staticMetaObjectE
                  but I see QAction and QActionGroup in the same library (QT += gui)
                  Do I miss some lib?

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

                  @jenya7
                  Same as before --- you need to look at the doc page! You are now getting an error about QActionGroup instead of QAction. So you need to look at the QActionGroup page for what it tells you you will need to add, just like before. And note that you are using Qt5 so you will need to be careful to look at that documentation, https://doc.qt.io/qt-5/qactiongroup.html, because at Qt6 (the default now when you search online) QActionGroup actually changed module!

                  but I see QAction and QActionGroup in the same library (QT += gui)

                  Yes in Qt6, not in Qt5!

                  1 Reply Last reply
                  2
                  • J jenya7

                    @jsulm said in How to compile a so file in order to load it as a library.:

                    @jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)

                    sorry to bother but I included
                    -L/usr/lib/arm-linux-gnueabihf/ -lQt5Gui
                    and QAction is good now but I get
                    undefined symbol: _ZN12QActionGroup16staticMetaObjectE
                    but I see QAction and QActionGroup in the same library (QT += gui)
                    Do I miss some lib?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #23

                    @jenya7 said in How to compile a so file in order to load it as a library.:

                    but I see QAction and QActionGroup

                    This is wrong, please look again...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    J 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @jenya7 said in How to compile a so file in order to load it as a library.:

                      but I see QAction and QActionGroup

                      This is wrong, please look again...

                      J Offline
                      J Offline
                      jenya7
                      wrote on last edited by jenya7
                      #24

                      @jsulm
                      Well. It shows no mercy. To make a single .so file I have to include ALL -lQt5** files and ALL object files in the build folder. Start to learn QMake file usage.

                      JonBJ 1 Reply Last reply
                      0
                      • J jenya7

                        @jsulm
                        Well. It shows no mercy. To make a single .so file I have to include ALL -lQt5** files and ALL object files in the build folder. Start to learn QMake file usage.

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

                        @jenya7
                        Not sure what you are saying here. In order to create a shared library file --- or for that matter an executable --- yes, you have to provide the linker with all the -l... libraries it will need to resolve all the references. And that includes other libraries which each one references. This will not be an unending/large number: there are only a limited number of libraries supplied for Qt, it's not like it's one for each class. Note btw that it will not statically include those library files into your executable or library --- it will use references to the shared library files to load at runtime.

                        J 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @jenya7
                          Not sure what you are saying here. In order to create a shared library file --- or for that matter an executable --- yes, you have to provide the linker with all the -l... libraries it will need to resolve all the references. And that includes other libraries which each one references. This will not be an unending/large number: there are only a limited number of libraries supplied for Qt, it's not like it's one for each class. Note btw that it will not statically include those library files into your executable or library --- it will use references to the shared library files to load at runtime.

                          J Offline
                          J Offline
                          jenya7
                          wrote on last edited by
                          #26

                          @JonB
                          But when I try to link the resulting so file to Python

                          from ctypes import *
                            
                          libc = CDLL("mylib.so")
                          

                          It throws exceptions till I include ALL files in so file build.

                          jsulmJ 1 Reply Last reply
                          0
                          • J jenya7

                            @JonB
                            But when I try to link the resulting so file to Python

                            from ctypes import *
                              
                            libc = CDLL("mylib.so")
                            

                            It throws exceptions till I include ALL files in so file build.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #27

                            @jenya7 said in How to compile a so file in order to load it as a library.:

                            till I include ALL files in so file build

                            You need to add all files which you link to your mylib.so (so, all the -l*.so)

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            2
                            • J Offline
                              J Offline
                              jenya7
                              wrote on last edited by jenya7
                              #28

                              Well. Finally I've build a so file. Added libraries till it stopped popping up "undefined symbol".
                              Now when Python loads the file it crashes with

                              Backend terminated or disconnected. Use 'Stop/Restart' to restart.

                              Too bad.

                              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