I create a simple console application "Hello world". First, I compile it with qmake: hello.pro
QT += core
QT -= gui
CONFIG += c++11
TARGET = hello
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
The application is builded normally and on a system without installed Qt and MinGW work fine. The size of the executable is 3.58MB.
Next, we compile the same source code using the QBS build system. Hello.qbs:
import qbs
CppApplication {
Depends{
name: "Qt"
submodules: [
"core",
]
}
name: "HelloWorld-minimal"
files: "main.cpp"
}
The executable file size is 4.35MB. The application requires "libwinthread-1.dll", "libstdc ++ - 6.dll" and "libgcc_s_dw2-1.dll".
A question: how correctly to build a static application in QBS with static linking of the above libraries and so that the size of the executable file was the same?
(With the standard build of the project, without statics, the sizes of executable files with Qmake and with Qbs are the same).
Answer was found:
import qbs
CppApplication {
Depends{
name: "Qt"
submodules: [
"core",
]
}
Properties {
condition: Qt.core.staticBuild
cpp.linkerFlags: [
"-static",
"-static-libgcc"
]
}
name: "HelloWorld-minimal"
files: "main.cpp"
}
The file size remains larger than when you compile with qmake (I assume that this is due to the fine-tuning of qbs). However, the main problem is solved: the application does not require additional dll's.
UPD: this solution work for QBS 1.6.0. For newest version (1.9.0) linker faild with error:
unrecognized -a option `tic-libgcc'
WTF?
SOLUTION: For QBS 1.9.0 you must used next code:
import qbs
CppApplication {
Depends{
name: "Qt"
submodules: [
"core",
]
}
Properties {
condition: Qt.core.staticBuild
cpp.driverFlags: [
"-static",
"-static-libgcc",
]
}
name: "HelloWorld-minimal"
files: "main.cpp"
}