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. Can't generate shared library on ubuntu and can't link statically to a static library
Qt 6.11 is out! See what's new in the release blog

Can't generate shared library on ubuntu and can't link statically to a static library

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 2.4k 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.
  • M Mohammedbie

    @sierdzio

    tried adding the following line with the same result :

    LIBS += /home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.a
    
    sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #6

    @Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:

    @sierdzio

    tried adding the following line with the same result :

    LIBS += /home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.a
    

    Sorry I should have been more specific. You can provide full path to -l flag:

    LIBS += -l/home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.a
    

    Or, another option is to use the file name specifier:

    unix:!macx: LIBS += -L$$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/ -l:libStaticTest.a
    

    Still, I don't know if that'll work.

    (Z(:^

    1 Reply Last reply
    2
    • M Offline
      M Offline
      Mohammedbie
      wrote on last edited by
      #7

      @sierdzio

      Tried both with the same result too.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mohammedbie
        wrote on last edited by
        #8

        something I didn't mention as I didn't think it was related , I build the shared library with Qt static library which I built from sources .
        Now when I try to build the shared library with the same version of Qt but dynamic it builds and generates .so file and the test application runs normally.
        What might cause this ?

        sierdzioS 1 Reply Last reply
        0
        • M Mohammedbie

          something I didn't mention as I didn't think it was related , I build the shared library with Qt static library which I built from sources .
          Now when I try to build the shared library with the same version of Qt but dynamic it builds and generates .so file and the test application runs normally.
          What might cause this ?

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by sierdzio
          #9

          @Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:

          something I didn't mention as I didn't think it was related , I build the shared library with Qt static library which I built from sources .
          Now when I try to build the shared library with the same version of Qt but dynamic it builds and generates .so file and the test application runs normally.
          What might cause this ?

          Hm, not sure but maybe your Qt config or mkspecs leak into definitions of your project when qmake is run.

          Try adding this in your shared lib .pro file:

          CONFIG -= staticlib
          CONFIG += shared
          

          (Z(:^

          1 Reply Last reply
          4
          • M Offline
            M Offline
            Mohammedbie
            wrote on last edited by
            #10

            Thank you very much .
            This solved it.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mohammedbie
              wrote on last edited by
              #11

              @sierdzio sorry for bothering you but one last thing how to convert those lines to a cmake line ?

              Thanks in advance

              sierdzioS 1 Reply Last reply
              0
              • M Mohammedbie

                @sierdzio sorry for bothering you but one last thing how to convert those lines to a cmake line ?

                Thanks in advance

                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #12

                @Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:

                @sierdzio sorry for bothering you but one last thing how to convert those lines to a cmake line ?

                Thanks in advance

                No idea, I don't know cmake well enough.

                (Z(:^

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mohammedbie
                  wrote on last edited by
                  #13

                  Ok thanks.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    Hi,

                    You set that in the call to add_library.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    3
                    • M Offline
                      M Offline
                      Mohammedbie
                      wrote on last edited by
                      #15

                      @SGaist

                      Hi ,
                      what I understood from cmake documentation is that add_library() configure the current project as a library and don't add an external library what I used instead was target_link_libraries() and it did the job indeed.

                      1 Reply Last reply
                      1
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        Ok, from you .pro file it looked like you were generating libraries.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        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