Using a static library in Qt Creator
LIBS += -L[path to lib] -l[name of lib]
Note! that filename of lib: lib[nameOfLib].a and you have to pass only original part -l[nameOfLib]
How to use static library in Qt 5.2?
You seem to have tried CONFIG+=static
, but that is not meant for this use case. That is used when you would like to use build your library to be static after the end of the build.
This is not the case here because you already have static Qt libraries available, so what you wish instead, to link those statically against your executable.
You would need to use this in your qmake project file:
LIBS += -L/path/to/the/static/QtCore -lQtCore
You could also use, albeit this would make the build-system less portable across different platforms:
LIBS += /path/to/the/statis/QtCore/libQtCore.a
windows – Qt create and use self-made static library
You can use QtCreators Subdirs project. Here's a detailed step by step instructions how to achieve that with QtCreator.
- Pick
Subdirs Project
from theNew Project
wizard menu.
- Add Subrojects by clicking on created Subdirs project with right
mouse button and selectingNew Subproject...
.
- By following wizards you should have a GUI or console Subproject and
a library Subproject. Then click on subproject where you want to link
your library subproject with right mouse button and selectAdd
.
Library...
- Select
Internal library
in the dialog and you will be prompted to
choose library you want to add.
Make sure your library subproject is included before gui/console
subproject as subdir project will fail to build.TEMPLATE = subdirs
SUBDIRS += \
LibProject \
CoreProject
How to have static linkage in a shared library in Qt Creator?
CONFIG += static
is the wrong flag, as stated by the documentation:
The target is a static library (lib only). The proper compiler flags
will automatically be added to the project.
If you want to link dependencies statically, and produce a shared library, you need to pass a flag to the linker, so add QMAKE_LFLAGS += -static
to your .pro
file.
A simple tests results in a 16kb dll without that flag, and a 995kb dll with it. Also, if dependency walker is to be trusted, the larger dll has no external dependencies, while the smaller depend on libgcc
and libstdc++
(it is just a trivial std::cout
test).
So evidently, you don't really need a static qt or qmake build. Tested with the "stock" 32bit mingw version of Qt.
Related Topics
Sort Based on Multiple Things in C++
Why Does Unique_Ptr Take Two Template Parameters When Shared_Ptr Only Takes One
What Can Make C++ Rtti Undesirable to Use
How to Enumerate/List All Installed Applications in Windows Xp
How Much Overhead Is There When Creating a Thread
Qt: How to Handle the Event of the User Pressing the 'X' (Close) Button
How to Detect Region of Large # of White Pixels Using Opencv
Making My Own Photo-Mosaic App with Qt Using C++
Getchar_Unlocked( ) VS Scanf() VS Cin
Optimize Template Replacement of a Switch
Generating One Class Member Per Variadic Template Argument
Exception Running Boost Asio Ssl Example
Should C++ Programmer Avoid Memset
How to Assign Multiple Values into a Struct at Once
Cannot Open Include File: 'Stdio.H' - Visual Studio Community 2017 - C++ Error
Link Error "Undefined Reference to '_Gxx_Personality_V0'" and G++