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. Static Library
Forum Updated to NodeBB v4.3 + New Features

Static Library

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 5.8k 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.
  • Q Offline
    Q Offline
    QProgrammer
    wrote on last edited by
    #1

    Hello guys

    I am trying to make a library for my project.

    I started with a minimal test sample to check how its working.

    1-I have made a library that contain a Class with a method

    2-I compile it and get Dll and Lib

    3- In main aplication i add this lib to .pro and tested library successfully.

    Now, i want to get rid of DLL and use lib file as an static library.

    So i added these to my library .pro file

    @CONFIG+=staticlib
    CONFIG-=dll@

    Or just

    @CONFIG+=staticlib@

    Now, i get lib file after compile, but i can not use it in my project and i get Unresolved external symbols... errors

    when i remove CONFIG+=staticlib , it works but i need to distribute dll too.

    So the question is : is it possible to have my own static library in Qt (none-commercial license)?

    If yes, what is wrong with my approach ?

    Thanks for your help

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @ CONFIG += staticlib
      @
      To build your library project.

      Then you need to address the reason the project using your library is not finding the library during linking. You need to look at the LIBS variable in that project.
      "Declaring Other Libraries":http://qt-project.org/doc/qt-4.8/qmake-project-files.html#declaring-other-libraries

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        If you are using Qt Creator ,there is a separate "wizard" for a static lib. That is one of my problems before (until now), that is why you get errors. They have separated the "format" for static and shared libraries so everytime you need to create a library for both, you need to create a separate project.

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          QProgrammer
          wrote on last edited by
          #4

          [quote author="ChrisW67" date="1363751402"]@ CONFIG += staticlib
          @
          To build your library project.

          Then you need to address the reason the project using your library is not finding the library during linking. You need to look at the LIBS variable in that project.
          "Declaring Other Libraries":http://qt-project.org/doc/qt-4.8/qmake-project-files.html#declaring-other-libraries[/quote]

          Yes, the problem is that i dont know how to address it. Because settings and paths are correct and it works fine with the .Lib file when i dont use "CONFIG += staticlib"
          but it does not work with same settings when i use "CONFIG += staticlib" to .pro file.

          So, the problem is difference between static .lib files in static mode and normal mode not from settings and paths. Am i right?

          i use these to use library in my project :

          @INCLUDEPATH +="G:/TestLib/testLib"
          LIBS +=-l"G:/Build/debug/testLib"@

          Is there any extra option that specify its a dynamic or static ?
          It confusing , i read "this article":http://qt-project.org/wiki/How_to_create_a_library_with_Qt_and_use_it_in_an_application and nothing is wrong with my code

          Are you guys sure there is no restriction with free version of Qt ?

          [quote author="Code_ReaQtor" date="1363761818"]If you are using Qt Creator ,there is a separate "wizard" for a static lib. That is one of my problems before (until now), that is why you get errors. They have separated the "format" for static and shared libraries so everytime you need to create a library for both, you need to create a separate project.[/quote]

          Yes, i use Qt Creator. Are you sure ? I can not find a separate wizard for static libs. i use this :

          !http://www.pixentral.com/pics/1eeq1OhrsuJ9QFPJLC7eXwO6Y4Bel.png(http://www.pixentral.com/pics/1eeq1OhrsuJ9QFPJLC7eXwO6Y4Bel.png)!

          Please, where can i find that wizard you are talking about?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Code_ReaQtor
            wrote on last edited by
            #5

            @QProgrammer, after you click "choose", you will see this:
            !http://64.19.142.10/www.pixentral.com/pics/1EUPtjh4Tns6VZYUaMa4FVqjdfe.png_hyuncompressed(Qt library wizard)!

            You will see separate choices for shared and statically linked libraries. one of which produces 3 files and the other produces 2. Adding CONFIG += staticlib to a "shared-created" library will produce linking errors.

            Please visit my open-source projects at https://github.com/Code-ReaQtor.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It doesn't matter if he uses the wizard or not. The only real difference is the CONFIG += staticlib line in the .pro file and import/export macros for shared library.

              Since you started with a dynamic library my guess is that you have your exported library symbols marked with <whatever your lib name is>SHARED_EXPORT macros. You should remove these or redefine it to "nothing" for static linking.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                QProgrammer
                wrote on last edited by
                #7

                [quote author="Code_ReaQtor" date="1363775884"]@QProgrammer, after you click "choose", you will see this:
                !http://64.19.142.10/www.pixentral.com/pics/1EUPtjh4Tns6VZYUaMa4FVqjdfe.png_hyuncompressed(Qt library wizard)!

                You will see separate choices for shared and statically linked libraries. one of which produces 3 files and the other produces 2. Adding CONFIG += staticlib to a "shared-created" library will produce linking errors.[/quote]

                Hey man! You rock!

                Sorry i didn't noticed that combo box in that wizard .
                Its working now! thank you for your help.

                The problem was that we don't need Q_DECL_EXPORT and Q_DECL_IMPORT for static libraries!
                which is not mentioned in that stupid illusory article explicitly.

                You saved my time, i appreciate it :)

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Code_ReaQtor
                  wrote on last edited by
                  #8

                  [quote author="Krzysztof Kawa" date="1363779944"]It doesn't matter if he uses the wizard or not. The only real difference is the CONFIG += staticlib line in the .pro file and import/export macros for shared library.

                  Since you started with a dynamic library my guess is that you have your exported library symbols marked with <whatever your lib name is>SHARED_EXPORT macros. You should remove these or redefine it to "nothing" for static linking.[/quote]

                  Yes, that is precisely the difference between shared and static files generated by Qt Creator. I find it NOT very helpful since you can't easily shift from shared to static and vice versa.

                  It will be helpful if Qt Creator can generate files that are compatible for both without any file modification.

                  @QProgrammer, sure no problem! If your problem is solved, please edit the title and add "[SOLVED]" to it.

                  Please visit my open-source projects at https://github.com/Code-ReaQtor.

                  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