⬆️ ⬇️

QtCreator: Qt cross-compiling from linux 64 to linux 32, win32, win64 and Mac OS X; upx, usb, dmg, etc





The Qt library allows you to make truly cross-platform applications. Once written code can be compiled for many operating systems. But the problem is precisely the word "compile", because it means that you need to reboot under the target system, have a customized development environment in it, an installed and configured library zoo. Rescues cross-compilation - a compilation that produces executable code for a platform other than the one on which it is executed.



Cross compiling for Windows 64


Usually one of the most requested problems is building a Windows version of your application, originally developed for Linux. An example of solving this problem can be seen here or in Russian . You need to create the mkspecs configuration, put the Qt files in the appropriate directories and that's it. Compiling Qt in this case is not necessary, you can download the binaries from the official site.

There are several drawbacks to this approach: 1) QtCreator does not know anything about the library installed in this way; 2) The official Qt build for Windows x64 does not exist. And if the first problem can somehow be fought, then only the compilation will help against the second ...



Before cross-compiling, do not forget to put the cross-compiler directly (it is searched in the package by the name manager “mingw”). And download the qt-everywhere source from the official site. In the mkspecs directory of the unpacked archive, copy the win32-g ++ folder to win64-x-g ++ and adjust the contents of the qmake.conf file. I got the following:

Hidden text
# # qmake configuration for win64-x-g++ # # Written for MinGW # # Cross compile example for i686-w64-mingw32-g++: # configure -xplatform win32-g++ -device-option CROSS_COMPILE=i686-w64-mingw32- # MAKEFILE_GENERATOR = MINGW load(device_config) equals(QMAKE_HOST.os, Windows): EXE_SUFFIX = .exe TEMPLATE = app CONFIG += qt warn_on release link_prl copy_dir_files debug_and_release debug_and_release_target precompile_header QT += core gui DEFINES += UNICODE #QT_LARGEFILE_SUPPORT QMAKE_COMPILER_DEFINES += __GNUC__ WIN WIN32 WIN64 QMAKE_EXT_OBJ = .o QMAKE_EXT_RES = _res.o QMAKE_CC = $${CROSS_COMPILE}gcc QMAKE_LEX = flex QMAKE_LEXFLAGS = QMAKE_YACC = byacc QMAKE_YACCFLAGS = -d QMAKE_CFLAGS = -pipe -m64 QMAKE_CFLAGS_DEPS = -M QMAKE_CFLAGS_WARN_ON = -Wall -Wextra QMAKE_CFLAGS_WARN_OFF = -w QMAKE_CFLAGS_RELEASE = -O2 QMAKE_CFLAGS_DEBUG = -g QMAKE_CFLAGS_YACC = -Wno-unused -Wno-parentheses QMAKE_CXX = $${CROSS_COMPILE}g++ QMAKE_CXXFLAGS = $$QMAKE_CFLAGS QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD QMAKE_CXXFLAGS_RTTI_ON = -frtti QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions QMAKE_INCDIR = /usr/x86_64-w64-mingw32/include QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS] QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS] QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -o $obj $src QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $obj $src QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< QMAKE_LINK = $${CROSS_COMPILE}g++ QMAKE_LINK_C = $${CROSS_COMPILE}gcc #QMAKE_LFLAGS = -m64 QMAKE_LFLAGS = -m64 -mthreads -static-libgcc -static -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mwindows QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads QMAKE_LFLAGS_EXCEPTIONS_OFF = QMAKE_LFLAGS_RELEASE = -Wl,-s QMAKE_LFLAGS_DEBUG = QMAKE_LFLAGS_CONSOLE = -Wl,-subsystem,console QMAKE_LFLAGS_WINDOWS = -Wl,-subsystem,windows QMAKE_LFLAGS_DLL = -shared QMAKE_LINK_OBJECT_MAX = 10 QMAKE_LINK_OBJECT_SCRIPT= object_script QMAKE_PREFIX_STATICLIB = lib QMAKE_EXTENSION_STATICLIB = a QMAKE_LIBS = QMAKE_LIBS_CORE = -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 QMAKE_LIBS_GUI = -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lws2_32 -lole32 -luuid -luser32 -ladvapi32 QMAKE_LIBS_NETWORK = -lws2_32 QMAKE_LIBS_OPENGL = -lglu32 -lopengl32 -lgdi32 -luser32 QMAKE_LIBS_COMPAT = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32 QMAKE_LIBS_QT_ENTRY = -lmingw32 -lqtmain !isEmpty(QMAKE_SH) { MINGW_IN_SHELL = 1 QMAKE_DIR_SEP = / QMAKE_QMAKE ~= s,\\\\,/, QMAKE_COPY = cp QMAKE_COPY_DIR = cp -r QMAKE_MOVE = mv QMAKE_DEL_FILE = rm QMAKE_MKDIR = mkdir -p QMAKE_DEL_DIR = rmdir QMAKE_CHK_DIR_EXISTS = test -d } else { QMAKE_COPY = copy /y QMAKE_COPY_DIR = xcopy /s /q /y /i QMAKE_MOVE = move QMAKE_DEL_FILE = del QMAKE_MKDIR = mkdir QMAKE_DEL_DIR = rmdir QMAKE_CHK_DIR_EXISTS = if not exist } QMAKE_MOC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}moc$${EXE_SUFFIX} QMAKE_UIC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}uic$${EXE_SUFFIX} QMAKE_IDC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}idc$${EXE_SUFFIX} QMAKE_IDL = midl QMAKE_LIB = $${CROSS_COMPILE}ar -ru QMAKE_RC = $${CROSS_COMPILE}windres QMAKE_ZIP = zip -r -9 QMAKE_STRIP = $${CROSS_COMPILE}strip QMAKE_STRIPFLAGS_LIB += --strip-unneeded load(qt_config) 


In fact, only the paths were replaced in the specification file.

')

I ran configure with the following parameters:

./configure -xplatform win64-x-g++ CROSS_COMPILE=x86_64-w64-mingw32- -prefix /usr/local/qt4win64 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast -nomake demos -nomake examples -nomake tools -device-option -little-endian -qt-zlib -qt-libpng -qt-libjpeg -openssl-linked -no-fontconfig -no-3dnow -no-ssse3 -continue

Here I collect the minimum version of Qt without webkit, phonon, multimedia, etc. For a complete list of options, see the command ./configure --help



Accordingly, for such an assembly, g ++ - mingw-w64-x86-64 package should be installed, containing x86_64-w64-mingw32- g ++ (the package should be installed separately in the ubuntu package).



Next make && sudo make install . At the first stage of compilation, the native system compiler is used; it collects the necessary linux utilities that will be used to build windows-binaries.

After installing, I have a PE32 + DLL and several ELF 64-bit LSB executables in / usr / local / qt4win64 / bin , including: qmake, uic, moc, rcc . Here they will come in handy for QtCreator!



After installation, do not delete the unpacked directory - it is used.



Cross compiling for Windows 32


Similar to compiling for Win64. Except for the fact that there is an official build, and the library itself is not necessary to compile! It is enough to collect qmake, uic, moc, rcc .



configure:

Hidden text
./configure -xplatform win32-x-g++ -prefix /usr/local/qt4win32 CROSS_COMPILE=i686-w64-mingw32- -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast -nomake demos -nomake examples -nomake tools -device-option -little-endian -qt-zlib -qt-libpng -qt-libjpeg -openssl-linked -no-fontconfig -no-3dnow -no-ssse3 -continue



qmake.conf

Hidden text
 # # qmake configuration for win32-x-g++ # # Written for MinGW # # Cross compile example for i686-w64-mingw32-g++: # configure -xplatform win32-g++ -device-option CROSS_COMPILE=i686-w64-mingw32- # MAKEFILE_GENERATOR = MINGW load(device_config) equals(QMAKE_HOST.os, Windows): EXE_SUFFIX = .exe TEMPLATE = app CONFIG += qt warn_on release link_prl copy_dir_files debug_and_release debug_and_release_target precompile_header QT += core gui DEFINES += UNICODE #QT_LARGEFILE_SUPPORT QMAKE_COMPILER_DEFINES += __GNUC__ WIN WIN32 QMAKE_EXT_OBJ = .o QMAKE_EXT_RES = _res.o QMAKE_CC = $${CROSS_COMPILE}gcc QMAKE_LEX = flex QMAKE_LEXFLAGS = QMAKE_YACC = byacc QMAKE_YACCFLAGS = -d QMAKE_CFLAGS = -pipe -m32 QMAKE_CFLAGS_DEPS = -M QMAKE_CFLAGS_WARN_ON = -Wall -Wextra QMAKE_CFLAGS_WARN_OFF = -w QMAKE_CFLAGS_RELEASE = -O2 QMAKE_CFLAGS_DEBUG = -g QMAKE_CFLAGS_YACC = -Wno-unused -Wno-parentheses QMAKE_CXX = $${CROSS_COMPILE}g++ QMAKE_CXXFLAGS = $$QMAKE_CFLAGS QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD QMAKE_CXXFLAGS_RTTI_ON = -frtti QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions QMAKE_INCDIR = /usr/i686-w64-mingw32/include QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS] QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS] QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -o $obj $src QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $obj $src QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< QMAKE_LINK = $${CROSS_COMPILE}g++ QMAKE_LINK_C = $${CROSS_COMPILE}gcc QMAKE_LFLAGS = -m32 -mthreads -static-libgcc -static -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mwindows QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads QMAKE_LFLAGS_EXCEPTIONS_OFF = QMAKE_LFLAGS_RELEASE = -Wl,-s QMAKE_LFLAGS_DEBUG = QMAKE_LFLAGS_CONSOLE = -Wl,-subsystem,console QMAKE_LFLAGS_WINDOWS = -Wl,-subsystem,windows QMAKE_LFLAGS_DLL = -shared QMAKE_LINK_OBJECT_MAX = 10 QMAKE_LINK_OBJECT_SCRIPT= object_script QMAKE_PREFIX_STATICLIB = lib QMAKE_EXTENSION_STATICLIB = a QMAKE_LIBS = QMAKE_LIBS_CORE = -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 QMAKE_LIBS_GUI = -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lws2_32 -lole32 -luuid -luser32 -ladvapi32 QMAKE_LIBS_NETWORK = -lws2_32 QMAKE_LIBS_OPENGL = -lglu32 -lopengl32 -lgdi32 -luser32 QMAKE_LIBS_COMPAT = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32 QMAKE_LIBS_QT_ENTRY = -lmingw32 -lqtmain !isEmpty(QMAKE_SH) { MINGW_IN_SHELL = 1 QMAKE_DIR_SEP = / QMAKE_QMAKE ~= s,\\\\,/, QMAKE_COPY = cp QMAKE_COPY_DIR = cp -r QMAKE_MOVE = mv QMAKE_DEL_FILE = rm QMAKE_MKDIR = mkdir -p QMAKE_DEL_DIR = rmdir QMAKE_CHK_DIR_EXISTS = test -d } else { QMAKE_COPY = copy /y QMAKE_COPY_DIR = xcopy /s /q /y /i QMAKE_MOVE = move QMAKE_DEL_FILE = del QMAKE_MKDIR = mkdir QMAKE_DEL_DIR = rmdir QMAKE_CHK_DIR_EXISTS = if not exist } QMAKE_MOC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}moc$${EXE_SUFFIX} QMAKE_UIC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}uic$${EXE_SUFFIX} QMAKE_IDC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}idc$${EXE_SUFFIX} QMAKE_IDL = midl QMAKE_LIB = $${CROSS_COMPILE}ar -ru QMAKE_RC = $${CROSS_COMPILE}windres QMAKE_ZIP = zip -r -9 QMAKE_STRIP = $${CROSS_COMPILE}strip QMAKE_STRIPFLAGS_LIB += --strip-unneeded load(qt_config) 




Cross compilation for Mac OS X


Cross compilation for poppy is also very similar, except that you will need to compile and compiler. I collected this instruction . It took a full day of time and a lot of nerves. The process will need a working Mac OS X (at least on a virtual machine) with Xcode installed in order to take the necessary files from there. When compiling your Qt applications running Mac OS X is not needed.



configure:

Hidden text
./configure -xplatform macx-x-g++ -prefix /usr/x86_64-apple-darwin11/usr/Qt CROSS_COMPILE=/usr/x86_64-apple-darwin11/usr/bin/x86_64-apple-darwin11- -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast -nomake demos -nomake examples -nomake tools -device-option -little-endian -qt-zlib -qt-libpng -qt-libjpeg -openssl-linked -no-fontconfig -no-3dnow -no-ssse3 -continue


qmake.conf:

Hidden text
 #macx-x-g++ (different from g++.conf) # # qmake configuration for macx-g++ # # Mac OS X + command-line compiler # MAKEFILE_GENERATOR = UNIX TARGET_PLATFORM = macx TEMPLATE = app CONFIG += qt warn_on release app_bundle incremental global_init_link_order lib_version_first plugin_no_soname link_prl QT += core gui QMAKE_INCREMENTAL_STYLE = sublib #include(../common/mac.conf) # # qmake configuration for common Mac OS X # #QMAKE_RESOURCE = /Developer/Tools/Rez QMAKE_EXTENSION_SHLIB = dylib QMAKE_INCDIR = /usr/x86_64-apple-darwin11/usr/include QMAKE_LIBDIR = QMAKE_INCDIR_QT = /usr/x86_64-apple-darwin11/usr/Qt/include QMAKE_LIBDIR_QT = /usr/x86_64-apple-darwin11/usr/Qt/lib QMAKE_INCDIR_OPENGL = /System/Library/Frameworks/OpenGL.framework/Headers \ /System/Library/Frameworks/AGL.framework/Headers/ QMAKE_FRAMEWORKDIR_QT= /usr/x86_64-apple-darwin11/usr/QtFrameworks QMAKE_FIX_RPATH = install_name_tool -id QMAKE_LFLAGS_RPATH = QMAKE_LIBS_DYNLOAD = QMAKE_LIBS_OPENGL = -framework OpenGL -framework AGL QMAKE_LIBS_OPENGL_QT = $$QMAKE_LIBS_OPENGL QMAKE_LIBS_THREAD = QMAKE_MOC = $$[QT_INSTALL_BINS]/moc QMAKE_UIC = $$[QT_INSTALL_BINS]/uic QMAKE_AR = /usr/x86_64-apple-darwin11/usr/bin/x86_64-apple-darwin11-ar cq QMAKE_RANLIB = /usr/x86_64-apple-darwin11/usr/bin/x86_64-apple-darwin11-ranlib -s QMAKE_TAR = tar -cf QMAKE_GZIP = gzip -9f QMAKE_COPY = cp -f QMAKE_COPY_FILE = $$QMAKE_COPY QMAKE_COPY_DIR = $$QMAKE_COPY -R QMAKE_MOVE = mv -f QMAKE_DEL_FILE = rm -f QMAKE_DEL_DIR = rmdir QMAKE_CHK_DIR_EXISTS = test -d QMAKE_MKDIR = mkdir -p QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.5 # overridden to 10.5 for Cocoa on the compiler command line # # qmake configuration for common unix # QMAKE_LEX = flex QMAKE_LEXFLAGS += QMAKE_YACC = yacc QMAKE_YACCFLAGS += -d QMAKE_YACCFLAGS_MANGLE += -p $base -b $base QMAKE_YACC_HEADER = $base.tab.h QMAKE_YACC_SOURCE = $base.tab.c QMAKE_PREFIX_SHLIB = lib QMAKE_PREFIX_STATICLIB = lib QMAKE_EXTENSION_STATICLIB = a #include(../common/gcc-base-macx.conf) # # This file is used as a basis for the following compilers: # # - The QNX qcc compiler # # The only difference between this and gcc-base.conf is that -pipe is removed # as it's on by default in qcc (and has an analogous -nopipe option) # QMAKE_CFLAGS += QMAKE_CFLAGS_DEPS += -M QMAKE_CFLAGS_WARN_ON += -Wall -W QMAKE_CFLAGS_WARN_OFF += -w QMAKE_CFLAGS_RELEASE += -O2 QMAKE_CFLAGS_DEBUG += -g QMAKE_CFLAGS_SHLIB += -fPIC QMAKE_CFLAGS_STATIC_LIB += -fPIC QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden QMAKE_CXXFLAGS += $$QMAKE_CFLAGS QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS -fvisibility-inlines-hidden QMAKE_LFLAGS += QMAKE_LFLAGS_DEBUG += QMAKE_LFLAGS_APP += QMAKE_LFLAGS_RELEASE += # # Base qmake configuration for GCC on Mac OS X # # Before making changes to this file, please read the comment in # gcc-base.conf, to make sure the change goes in the right place. # # To verify that your change has the desired effect on the final configuration # you can use the manual test in tests/manual/mkspecs. # QMAKE_COMPILER_DEFINES += __APPLE__ __GNUC__ QMAKE_CFLAGS_X86 += -arch i386 QMAKE_CFLAGS_X86_64 += -arch x86_64 QMAKE_CFLAGS_PPC += -arch ppc QMAKE_CFLAGS_PPC_64 += -arch ppc64 QMAKE_CFLAGS_DWARF2 += -gdwarf-2 QMAKE_CXXFLAGS_X86 += $$QMAKE_CFLAGS_X86 QMAKE_CXXFLAGS_X86_64 += $$QMAKE_CFLAGS_X86_64 QMAKE_CXXFLAGS_PPC += $$QMAKE_CFLAGS_PPC QMAKE_CXXFLAGS_PPC_64 += $$QMAKE_CFLAGS_PPC_64 QMAKE_CXXFLAGS_DWARF2 += $$QMAKE_CFLAGS_DWARF2 QMAKE_OBJECTIVE_CFLAGS = $$QMAKE_CFLAGS QMAKE_OBJECTIVE_CFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON QMAKE_OBJECTIVE_CFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF QMAKE_OBJECTIVE_CFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG QMAKE_OBJECTIVE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE QMAKE_OBJECTIVE_CFLAGS_HIDESYMS = $$QMAKE_CXXFLAGS_HIDESYMS QMAKE_OBJECTIVE_CFLAGS_X86 = $$QMAKE_CFLAGS_X86 QMAKE_OBJECTIVE_CFLAGS_X86_64 = $$QMAKE_CFLAGS_X86_64 QMAKE_OBJECTIVE_CFLAGS_PPC = $$QMAKE_CFLAGS_PPC QMAKE_OBJECTIVE_CFLAGS_PPC_64 = $$QMAKE_CFLAGS_PPC_64 QMAKE_LFLAGS_X86 += $$QMAKE_CFLAGS_X86 QMAKE_LFLAGS_X86_64 += $$QMAKE_CFLAGS_X86_64 QMAKE_LFLAGS_PPC += $$QMAKE_CFLAGS_PPC QMAKE_LFLAGS_PPC_64 += $$QMAKE_CFLAGS_PPC_64 QMAKE_LFLAGS += -headerpad_max_install_names QMAKE_LFLAGS_SHLIB += -single_module -dynamiclib QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB QMAKE_LFLAGS_INCREMENTAL += -undefined suppress -flat_namespace QMAKE_LFLAGS_SONAME += -install_name$${LITERAL_WHITESPACE} QMAKE_LFLAGS_VERSION += -current_version$${LITERAL_WHITESPACE} QMAKE_LFLAGS_COMPAT_VERSION += -compatibility_version$${LITERAL_WHITESPACE} # # Qmake configuration for the GNU C++ compiler # # Before making changes to this file, please read the comment in # gcc-base.conf, to make sure the change goes in the right place. # # To verify that your change has the desired effect on the final configuration # you can use the manual test in tests/manual/mkspecs. # QMAKE_CC = /usr/x86_64-apple-darwin11/usr/bin/x86_64-apple-darwin11-g++ QMAKE_LINK_C = $$QMAKE_CC -F/usr/x86_64-apple-darwin11/usr/Frameworks QMAKE_LINK_C_SHLIB = $$QMAKE_CC -F/usr/x86_64-apple-darwin11/usr/Frameworks QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g QMAKE_CXX = /usr/x86_64-apple-darwin11/usr/bin/x86_64-apple-darwin11-g++ QMAKE_LINK = /usr/x86_64-apple-darwin11/usr/bin/x86_64-apple-darwin11-g++ -F/usr/x86_64-apple-darwin11/usr/Frameworks QMAKE_LINK_SHLIB = $$QMAKE_CXX -F/usr/x86_64-apple-darwin11/usr/Frameworks QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO QMAKE_PCH_OUTPUT_EXT = .gch QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT} QMAKE_CFLAGS_USE_PRECOMPILE = -include ${QMAKE_PCH_OUTPUT_BASE} QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT} QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE #include(../common/g++-macx.conf) # # Qmake configuration for the GNU C++ compiler on Mac OS X # # Before making changes to this file, please read the comment in # gcc-base.conf, to make sure the change goes in the right place. # # To verify that your change has the desired effect on the final configuration # you can use the manual test in tests/manual/mkspecs. # QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_DWARF2 QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_DWARF2 QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO += -g $$QMAKE_CFLAGS_DWARF2 QMAKE_LFLAGS_STATIC_LIB += -all_load QMAKE_CFLAGS_X86_64 += -Xarch_x86_64 -mmacosx-version-min=10.5 QMAKE_CFLAGS_PPC_64 += -Xarch_ppc64 -mmacosx-version-min=10.5 QMAKE_CXXFLAGS_X86_64 = $$QMAKE_CFLAGS_X86_64 QMAKE_CXXFLAGS_PPC_64 = $$QMAKE_CFLAGS_PPC_64 QMAKE_OBJECTIVE_CFLAGS_X86_64 = $$QMAKE_CFLAGS_X86_64 QMAKE_OBJECTIVE_CFLAGS_PPC_64 = $$QMAKE_CFLAGS_PPC_64 QMAKE_LFLAGS_X86_64 = $$QMAKE_CFLAGS_X86_64 QMAKE_LFLAGS_PPC_64 = $$QMAKE_CFLAGS_PPC_64 QMAKE_OBJCFLAGS_PRECOMPILE = -x objective-c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT} QMAKE_OBJCFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE QMAKE_OBJCXXFLAGS_PRECOMPILE = -x objective-c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT} QMAKE_OBJCXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE load(qt_config) 


Remember, on Mac OS X, links to the .a library are not needed.



QtCreator setup


First you need to add to the list all installed compilers. Tools - Options - Build and Run - Toolkits:



QtCreator normally defines ABI normally, but it's best to double-check. You can also notice that the system x64 GCC in linux can also generate 32-bit applications. However, this does not negate the fact that 32-bit versions of libraries are also needed.



After compilers, you can add Qt profiles:



Here, when adding a profile, qmake, uic, moc, rcc collected earlier will be useful, because you need to select the directory with qmake . A yellow icon with an exclamation mark to the left of the profile means warning, but QtCreator can use such a Qt profile. But if the icon is red, then the profile is not working. This can happen if the directory structure is incorrect. Or if you delete the directory in which you compiled Qt.



The following settings need to be done in each created project.

To add a specific Qt profile, go to the “Projects” tab (Ctrl + 5) with the active project:





By default, only the Qt system profile is listed in the “Edit build configuration” list. But in the list of the “Add” button there are all Qt profiles added to the build parameters.



In the main assembly settings, you need to check the compiler library pair. So that both were from the same operating system.



The “qmake” and “Build” build steps QtCreator installs by default. And here I added the special stages "upx" and "dmgbuild" manually for the project. The “upx” stage is performed each time you click on the “Build project” button. However, if the executable file has not been changed, then upx will return an error that it has already processed the file. In case of an error, the next stage is not called, i.e. The dmg file will be updated only if upx worked successfully.



For the upx stage to work, it must be installed in the system. However, even working in a linux environment and delivered from the package manager upx can compress applications: linux32 / 64, win32, macos32 / 64. Not for all projects, upx-compression is really needed, the stage is shown rather for example.



For the “dmgbuild” stage I used the make_dmg script. He needs root rights, so he added the script to the / etc / sudoers file



Changes in the project file and use of third-party libraries


My project uses libusb , and this is not a part of Qt. It was also necessary to enable the platform-dependent HID implementation. The following lines were added to the project file:



 macx { INCLUDEPATH += $$PWD/libusbx/ SOURCES += BootLoader/HIDAPI/mac/hid.c LIBS += -framework IOKit -framework CoreFoundation -lusb-1.0 ICON = AqPicFlash.icns } win32: { INCLUDEPATH += $$PWD/libusbx/ LIBS += -lsetupapi -lole32 SOURCES += BootLoader/HIDAPI/windows/hid.cpp RC_FILE = WinIcon.rc } win32: !win64-x-g++ { LIBS += -L$$PWD/libusbx/ -lusb-1.0-32.dll } win64-x-g++ { LIBS += -L$$PWD/libusbx/ -lusb-1.0-64.dll } unix: !macx { CONFIG += link_pkgconfig PKGCONFIG += libusb-1.0 SOURCES += BootLoader/HIDAPI/linux/hid-libusb.c } 


In Mac OS X and Linux, we link with the system libusb, in Windows, depending on the bit length, we link with libusb-1.0-32.dll.a or libusb-1.0-64.dll.a . Remember that the .a file can be renamed, but the application will still depend on libusb-1.0.dll . In Linux, the parameters for libusb are taken through the system utility pkgconfig. In addition to libusb, we connect the necessary system libraries and icons for each operating system.



It is convenient to post the resulting files for different operating systems on directories. You can do it like this:

 macx { DESTDIR = mac OBJECTS_DIR = mac MOC_DIR = mac UI_DIR = mac RCC_DIR = mac } unix: !macx { DESTDIR = linux OBJECTS_DIR = linux MOC_DIR = linux UI_DIR = linux RCC_DIR = linux } win32 { DESTDIR = windows/release OBJECTS_DIR = windows MOC_DIR = windows UI_DIR = windows RCC_DIR = windows } win64-x-g++ { DESTDIR = win64/release OBJECTS_DIR = win64 MOC_DIR = win64 UI_DIR = win64 RCC_DIR = win64 } 


The target win64-x-g ++ refers to win32 , however in the project file it comes last and overwrites the settings.



Result


Now, to build an application for one or another operating system, just select the build type, as shown in the very first screenshot, and click "Build project"

Source: https://habr.com/ru/post/198142/



All Articles