You need three things:
- You need Qt itself built as a static library:
- You need said Qt statically linked to the runtime.
- You need to link your library statically to the runtime. This is handled automatically.
For all of it, you need to configure a custom Qt build with -static -static-runtime
arguments. Any executable/library you build using this Qt build will be statically linked to the runtime and statically linked to Qt (iff it uses Qt).
It is worth noting that none of the above requires any changes to your project's .pro
file. Conversely, there's nothing you can do to your project file to get the same effect, generally speaking. You have to get a properly configured Qt built, and everything will be handled from there.
There's no requirement on your library itself to use Qt, other than there being a project file that manages the build. For example, this would be a rudimentary library that doesn't use Qt nor C++:
TARGET = mylib
TEMPLATE = lib
CONFIG -= qt
SOURCES = mylib.c
HEADERS = mylib.h
As long as you invoke qmake
from a Qt configured as above, the shared library won't dynamically link to the language runtime (nor to Qt, but in this case it won't link to Qt at all!).