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

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 1.9k 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 Offline
    M Offline
    Mohammedbie
    wrote on last edited by
    #1

    Hi all,
    I started a new project in Qt creator and chose c++ library and from it dynamic library on ubuntu when I build the project I end up with .a file not .so can anybody explain to me what I am doing wrong ?

    second problem is that when I try to link the shared library against a static library through add library it appears as it will link statically as wanted and it build without any error but the deployed shared library is much smaller than the static library and when I test it using another program it throws an error of no definition of static library's class and functions.

    Any help would be greatly appreciated.
    Thanks in advance.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Can you share the relevant parts of your .pro files for both issues you mention?

      (Z(:^

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

        Thanks for the fast reply , here are the .pro files :

        shared library .pro :

        #-------------------------------------------------
        #
        # Project created by QtCreator 2018-12-11T23:18:12
        #
        #-------------------------------------------------
        
        QT       -= gui
        
        TARGET = DLLtest
        TEMPLATE = lib
        
        DEFINES += DLLTEST_LIBRARY
        
        # The following define makes your compiler emit warnings if you use
        # any feature of Qt which as been marked as deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # You can also make your code fail to compile if you use deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += dlltest.cpp
        
        HEADERS += dlltest.h\
                dlltest_global.h
        
        unix {
            target.path = /usr/lib
            INSTALLS += target
        }
        
        unix:!macx: LIBS += -L$$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/ -lStaticTest
        
        INCLUDEPATH += $$PWD/../StaticTest
        DEPENDPATH += $$PWD/../StaticTest
        
        unix:!macx: PRE_TARGETDEPS += $$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.a
        
        

        Static library .pro :

        #-------------------------------------------------
        #
        # Project created by QtCreator 2018-12-12T01:26:48
        #
        #-------------------------------------------------
        
        QT       -= gui
        
        TARGET = StaticTest
        TEMPLATE = lib
        CONFIG += staticlib
        
        # The following define makes your compiler emit warnings if you use
        # any feature of Qt which as been marked as deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # You can also make your code fail to compile if you use deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += statictest.cpp
        
        HEADERS += statictest.h
        unix {
            target.path = /usr/lib
            INSTALLS += target
        }
        
        

        Test program .pro :

        QT += core
        QT -= gui
        
        CONFIG += c++11
        
        TARGET = test
        CONFIG += console
        CONFIG -= app_bundle
        
        TEMPLATE = app
        
        SOURCES += main.cpp
        
        # The following define makes your compiler emit warnings if you use
        # any feature of Qt which as been marked deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # You can also make your code fail to compile if you use deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        
        
        unix:!macx: LIBS += -L$$PWD/./ -lDLLtest
        
        INCLUDEPATH += $$PWD/../DLLtest
        DEPENDPATH += $$PWD/../DLLtest
        
        
        
        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Hm, code looks good to be honest.

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

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

          Is there a .a in that folder? Perhaps you need to link specifically to .a and not use the general -l flag.

          (Z(:^

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

            @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 1 Reply Last reply
            0
            • 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