Static Library
-
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
-
@ 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 -
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 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 codeAre 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 :
Please, where can i find that wizard you are talking about?
-
@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.
-
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 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 :)
-
[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.