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. Regarding the static library loading fails
Forum Updated to NodeBB v4.3 + New Features

Regarding the static library loading fails

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 3.6k Views 2 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    First thing. a static library is linked into the application.
    So its not possible to load later using QLibrary.

    Via the LIBS += in pro file you
    tell it to look for "staticlib " in a sub folder to the project called Libraries.

    Is that correct?

    You can click the pro file, then right click the edit area and use the "add library" dialog
    then compare paths.

    https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

    http://stackoverflow.com/questions/1361229/using-a-static-library-in-qt-creator

    The add lib dialog
    http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

    1 Reply Last reply
    2
    • Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by
      #3

      correct me if i my understanding is wrong.
      If we include the libraries and header files created from one project and adding to the .pro file of another project, that means we are adding static library, linking to the application for the usage.

      First thing. a static library is linked into the application.
      So its not possible to load later using QLibrary.

      Via the LIBS += in pro file you

      as u mentioned @mrjj that means the library got created successfully and i have linked to my another application, so loading later using QLibrary is of no use.
      Is my understanding correct?.

      So only i am getting the error as cannot load library invalid ELF header,

      But still widget is showing.

      The link is below

      https://postimg.org/image/dvjexsohh/

      Pradeep Kumar
      Qt,QML Developer

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        A static lib must be linked into the application so QLibrary cannot be used.
        (it will report error)

        • But still widget is showing.

        so WidgetApplication comes from the static lib?

        Normally it complains if cant link what you ask of it so it sounds like you are in fact using the static lib but only u can tell :)

        1 Reply Last reply
        0
        • Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by Pradeep Kumar
          #5

          Yes i have used static lib , inherited the class from QWidget. So i am calling the class name as WidgetApplication.

          so .pro file of WidgetApplication. Is below

          https://postimg.org/image/el9nd8lx9/

          Pradeep Kumar
          Qt,QML Developer

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Ok so it seems to use the lib ?
            So it was working :)

            1 Reply Last reply
            1
            • Pradeep KumarP Offline
              Pradeep KumarP Offline
              Pradeep Kumar
              wrote on last edited by Pradeep Kumar
              #7

              Hmmmm

              came to know when we want to allocate the memory using the libraries created , then we need to go for using the class QLibrary.
              If we use static libraries linked to out application, memory will be allocated.

              Thanks,

              Pradeep Kumar
              Qt,QML Developer

              mrjjM 1 Reply Last reply
              0
              • Pradeep KumarP Pradeep Kumar

                Hmmmm

                came to know when we want to allocate the memory using the libraries created , then we need to go for using the class QLibrary.
                If we use static libraries linked to out application, memory will be allocated.

                Thanks,

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #8

                @Pradeep-Kumar
                Yes when using static lib, its 100% included into the application and you do not gain the feature on load on demand as you do
                with shared libs. So if you need to only have it active is needed - than dynamic library is better.
                Not that just linking the lib, might not use much extra as long no objects are allocated but the code is indeed
                always compiled into the app and in that way takes extra memory.

                Pradeep KumarP 1 Reply Last reply
                2
                • mrjjM mrjj

                  @Pradeep-Kumar
                  Yes when using static lib, its 100% included into the application and you do not gain the feature on load on demand as you do
                  with shared libs. So if you need to only have it active is needed - than dynamic library is better.
                  Not that just linking the lib, might not use much extra as long no objects are allocated but the code is indeed
                  always compiled into the app and in that way takes extra memory.

                  Pradeep KumarP Offline
                  Pradeep KumarP Offline
                  Pradeep Kumar
                  wrote on last edited by
                  #9

                  @mrjj said in Regarding the static library loading fails:

                  @Pradeep-Kumar
                  Yes when using static lib, its 100% included into the application and you do not gain the feature on load on demand as you do
                  with shared libs. So if you need to only have it active ia needed - than dynamic library is better.
                  Not that just linking the lib, might not use much extra as long no objects are allocated but the code is indeed
                  always compiled into the app and in that way takes extra memory.

                  Just explained nicely and ellaborated my previous post answer.
                  with the static lib, executable size also increases.

                  Got it man.

                  Pradeep Kumar
                  Qt,QML Developer

                  mrjjM 1 Reply Last reply
                  1
                  • Pradeep KumarP Pradeep Kumar

                    @mrjj said in Regarding the static library loading fails:

                    @Pradeep-Kumar
                    Yes when using static lib, its 100% included into the application and you do not gain the feature on load on demand as you do
                    with shared libs. So if you need to only have it active ia needed - than dynamic library is better.
                    Not that just linking the lib, might not use much extra as long no objects are allocated but the code is indeed
                    always compiled into the app and in that way takes extra memory.

                    Just explained nicely and ellaborated my previous post answer.
                    with the static lib, executable size also increases.

                    Got it man.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Pradeep-Kumar
                    executable size also increases.

                    Indeed it does. A plain empty default project compiled with static Qt is around 15 MB as the Qt dlls are compiled into it.
                    For debug builds, it can get insane big. exe > 200 MB!

                    1 Reply Last reply
                    2
                    • Pradeep KumarP Offline
                      Pradeep KumarP Offline
                      Pradeep Kumar
                      wrote on last edited by
                      #11

                      Then if i have to use QLibrary then shared libraries comes into picture, and then only i can use it.

                      Hmmmmmmm:))))))))))

                      Pradeep Kumar
                      Qt,QML Developer

                      mrjjM 1 Reply Last reply
                      0
                      • Pradeep KumarP Pradeep Kumar

                        Then if i have to use QLibrary then shared libraries comes into picture, and then only i can use it.

                        Hmmmmmmm:))))))))))

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @Pradeep-Kumar
                        If the lib is a Qt lib and the app that will use it - is a Qt app, I highly suggest you have a look at Qt plugins as
                        it is a smart(er?) way to use shared libs.

                        http://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html

                        The same way Creator uses its plugins , you can use for your app and libs.

                        it uses a interface design and its easier to handle than raw loading as it helps exporting QWidgets with more in
                        a nice manner. It takes a little to get up and running but after that its pretty easy to use.

                        http://doc.qt.io/qt-5/qtwidgets-tools-echoplugin-example.html

                        1 Reply Last reply
                        2
                        • Pradeep KumarP Offline
                          Pradeep KumarP Offline
                          Pradeep Kumar
                          wrote on last edited by
                          #13

                          Hi,

                          I got the output and it is working in multiple devices.
                          Thanks for the help and guidance provided.

                          So marking as Solved.

                          Thanks,

                          Pradeep Kumar
                          Qt,QML Developer

                          1 Reply Last reply
                          1

                          • Login

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