How do I make apps smaller with qmake and macdeployqt?
I have set QT = core gui in the projects .pro file and run qmake and macdeployqt on the resulting app.
The problem is that the program is bundling QtNetwork, QtScript, QtSvg etc. I've tried setting QT -= network script svg (and then make clean, rm -rf *.app, qmake, make).
In total the app is 32 MB.
.pro file:
TEMPLATE = app
TARGET = throw
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += x86_64 release
QT = core gui
unix {
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0
}
# Input
SOURCES += main.cpp
# Headers
HEADERS += throw.h
RESOURCES += throw.qrc
ICON = throw.png
mac {
QMAKE_INFO_PLIST = Info.plist
ICON = throw.icns
}
This is a great article about (re)building Qt statically and dynamically to reduce its size considerably: Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler
While this is talking about Qt in the windows context, it does give some good insight into how one would go about compiling for minimal size.
You could strip the binary afterwards in a post-build step. The Qt libraries themselves are shared by default.
Related
I have Qt Creator project. Every time I open the pro file from Qt VS tools, I only get x86 project. In Qt options, I have two compilers, x86 and x64 compiler (default). Even using x64 default compiler produces x86 project.
My project pro file looks like this.
TEMPLATE = app
TARGET = myApp
QT += qml quick core
CONFIG += c++11
HEADERS += main.h
SOURCES += main.cpp
RESOURCES += qml.qrc
# Default rules for deployment.
include(deployment.pri)
INCLUDEPATH += include \
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\windows.h\
MAKE_SPEC = $$split(QMAKESPEC, /)
contains(MAKE_SPEC, msvc2017_64):{
LIBS += -L"$$PWD/lib/x64" -lftd2xx
} else {
LIBS += -L"$$PWD/lib/x86" -lftd2xx
}
DISTFILES += deployment.pri \
lib/ftd2xx.lib \
ui/main.qml
SUBDIRS += myapp.pro
DESTDIR = bin
The platform is selected according to the current default Qt version (Qt VS Tools > Options > Default Qt/Win version). If an x64 Qt build is selected, new projects will be configured with the x64 platform.
as the title indicates, I am trying to compile a simple project in Qt that makes use of the addressbook.pb.h/addressbook.pb.cc files that are generated in the google protobuf3 tutorial for C++ users. Here is my .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2016-11-07T10:33:12
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = prototest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
../protobuf/examples/addressbook.pb.cc
HEADERS += mainwindow.h \
../protobuf/examples/addressbook.pb.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/Cellar/protobuf/3.1.0/include
LIBS += /usr/local/Cellar/protobuf/3.1.0
Unfortunately, this throws
:-1: error: can't map file, errno=22 file '/usr/local/Cellar/protobuf/3.1.0' for architecture x86_64
I'm stuck at this point. Any help would be greatly appreciated. I have been able to compile and run the exact same (addressbook.*) files using Xcode8.
Solved it: Add the following to the .pro file
macx: LIBS += -L$$PWD/../../../usr/local/Cellar/protobuf/3.1.0/lib/ -lprotobuf.11
INCLUDEPATH += $$PWD/../../../usr/local/Cellar/protobuf/3.1.0/include
DEPENDPATH += $$PWD/../../../usr/local/Cellar/protobuf/3.1.0/include
I should add how I arrived at this answer. Right click your project and select "Add Library->External Library", select your platform and enter your specific library (not path) that you want to add, and your include path (the options it gives you indicate such). Qt will generate the code and automatically add it to your .pro file.
I'm following this guide to install OpenCV for Qt: http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml. But this tutorial is made for Qt with mingw32 compiler kit.
Kindly suggest me the steps to install it on Visual Studio 2012 on Windows 7 64bit (with or without cmake).
You need to select your compiler not MinGW.
You then specify the compilers that will generate the project. In our case, they are the compilers of MinGW installed by default by Qt.
You need to select 64 bit Visual Studio 11.0. And when you finish configuration and click generate button cmake is going to generate you a solution file, all you need to do is open that solution file and compile it.
Use this guide http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html. If you will have problems with building Qt 5.x, use Qt 4.x - it's much easier to build it.
Ok, I was able to solve this problem by following the guide mentioned by cyriel:http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html.
And adding following lines to myproject.pro file:
INCLUDEPATH += C:\OpenCV\build\include
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_core244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_highgui244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_imgproc244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_calib3d244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_calib3d244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_contrib244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_core244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_features2d244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_flann244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_gpu244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_highgui244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_imgproc244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_legacy244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_ml244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_nonfree244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_objdetect244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_photo244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_stitching244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_ts244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_video244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_videostab244d.lib
By doing this, there is no need for additional compilation again by vsc2012. It also saves hard disk space. And anyone will be able to run their opencv project written in Qt5.1.
When I use qtcreator on mac, it creates universal binaries.
Does anyone know how to set it so it just creates a 'native' binary? (So i386' in my case?)
Qtcreator uses qmake as a buildsystem.
Google hasn't been my friend so far, I hope stackoverflow will.
EDIT:
my config file so far:
TARGET = mongowriter
CONFIG += console
CONFIG -= app_bundle
CONFIG += x86
#CONFIG -= ppc
TEMPLATE = app
INCLUDEPATH += /opt/local/include/.
INCLUDEPATH += ../mongodb/.
SOURCES += main.cpp
LIBS += /usr/local/lib/libmongoclient.a
LIBS += /opt/local/lib/libboost_thread-mt.a
LIBS += /opt/local/lib/libboost_filesystem.a
LIBS += /opt/local/lib/libboost_program_options.a
It still gives the error on the libmongoclient.a
The libboost libraries are all ok, but this is because I got them from macports with the +universal option.
Since mongoclient doesn't support universal I'm currently removing all the universal stuff. I was hoping to get 3 errors for the boost libs and that at l;east mongoclient would link.
At that point I could redo the whole macport story again but this time with universal removed.
Unfortunately it seems it still builds a universal binary since I still have the same linker errors.
thanks for the help
you can use the 'CONFIG' variable in your project file to specify which plattforms shall be supported to create a universial binary you use
CONFIG += x86 ppc
if you only need x86 you use
CONFIG += x86
I am having a problem with running an example from qt which uses win32 libraries. When I compile I don't get any errors but when I run it is not able to open the application (.exe) file in Windows 7. But when I compile this example in WindowsXP it works fine. Can anyone let me know whether I need to change my .pro file in order to get it worked under Windows 7?
Here is my .pro file:
# -------------------------------------------------
# Project created by QtCreator 2010-04-16T11:45:43
# -------------------------------------------------
QT += network
QT += xml
QT += opengl
TARGET = Application
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp \
Tools.cpp \
Objects.cpp
HEADERS += mainwindow.h \
Tools.h\
Objects.h
unix {
OBJECTS_DIR = .obj
MOC_DIR = .moc
}
# UNIX installation
isEmpty(PREFIX):PREFIX = /usr/local
unix {
headers.path = $$PREFIX/include/ZIP
headers.files = $$HEADERS
target.path = $$PREFIX/lib
INSTALLS += headers \
target
}
!mac:x11:LIBS += -ldns_sd
win32:LIBS += -ldnssd
LIBPATH = C:/Temp/mDNSResponder-107.6/mDNSWindows/DLL/Debug
INCLUDEPATH += c:/Temp/mDNSResponder-107.6/mDNSShared
You can use Dependency Walker to help you find out what Qt DLLs are needed and copy them to the same folder as the .exe.
Your problem is probably because Windows can't find the Qt libraries.
Try placing the required Qt libraries (for instance QtNetwork4.dll, etc...) in the same directory as your .exe and see if it works.