I want to create a GUI application for Windows and Linux environments, so this time I will compile and develop a QT framework that supports cross-platform in the Ubuntu environment, and try the cross-compilation method that runs in the Windows environment.
MinGW Install the Windows compiler mingw-w64 in a Linux environment.
sudo apt-get install binutils-mingw-w64-x86-64
sudo apt-get install mingw-w64-common
sudo apt-get install mingw-w64-x86-64-dev
sudo apt-get install mingw-w64-tools
sudo apt-get install gcc-mingw-w64-base
sudo apt-get install gcc-mingw-w64-x86-64
sudo apt-get install g++-mingw-w64-x86-64
Use Win64 + pthread version (posix)
update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
Qt Source Get the top repository
PKG=qt5 VER=5.13.2 TAG=v$VER
QTDIR=~/Qt
mkdir -p "$QTDIR/$VER/mingw_64"
mkdir -p "$QTDIR/$VER/src"
cd "$QTDIR/$VER/src"
git clone --depth 1 git://code.qt.io/qt/qt5.git $PKG
cd $PKG
git fetch --depth 1 origin tag $TAG
git checkout -f $TAG
Get submodule Qt5 is made up of a large number of submodules. Since it takes time to download the entire history of submodules, This time we will download only the qtbase submodules needed for development with Qt Widgets.
for module in qtbase; do
git submodule update --init --depth 1 --progress $module
done
git clean -dfX
git submodule foreach --recursive git clean -dfX
Configuring Qt Cross-compile Qt for Windows environment.
./configure \
-xplatform win32-g++ \
-device-option CROSS_COMPILE=/usr/bin/x86_64-w64-mingw32- \
--prefix="$QTDIR/$VER/mingw_64" \
-opensource \
-confirm-license \
-developer-build \
-no-compile-examples \
-nomake examples \
-opengl desktop \
-L/usr/x86_64-w64-mingw32/lib \
QMAKE_LIBS+="-lws2_32"
Make Qt Since the compilation time is long, compile in parallel with the number of CPU slaves. If the compilation ends abnormally due to lack of PC memory, reduce the number of parallel compilations and compile. "When compiling in a 16-slade environment: memory 8G, takes about 10 minutes"
J=$(grep -cs '^processor' /proc/cpuinfo || echo 2)
echo $J
make -j $J
Installation Qt
J=$(grep -cs '^processor' /proc/cpuinfo || echo 2)
echo $J
make -j $J install
Qt Creator
Add the MinGW compiler in Qt Creator. Add MinGW C and C ++ compilers from [Tools] [Options] [Kits] [Compiler] [Add] [MinGW].
Add "QTDIR/VER/mingw_64/bin/qmake" built and installed from [Tools] [Options] [Kits] [Qt version] [Add].
Add from [Tools] [Options] [Kits] [Kits] [Add]. Compiler: Select the added MinGW compiler Qt version: Select the added MinGW Qt version Make the added MinGW Qt kit the default
Create from [File] [New Project].
Enter the name and location of the application
Select the added MinGW Qt kit and enter the build location
Use the default setting for class information
Complete the settings
Add button to GUI Double-click Forms/mainwindow.ui to open the Forms edit screen Drag and drop [Buttons] [Push Button] onto the Form
Build Qt Application from [Build] [Rebuild Project].
Copy the built qt_gui_app.exe, MinGW DLL, and Qt DLL to Windows.
Original: /usr/lib/gcc/x86_64-w64-mingw32/7.3-posix/libgcc_s_seh-1.dll /usr/lib/gcc/x86_64-w64-mingw32/7.3-posix/libstdc++-6.dll /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll Copy destination: Same folder as exe
Copy source: QTDIR/VER/mingw_64/bin Qt5Core.dll、Qt5Gui.dll、Qt5Widgets.dll Copy destination: Same folder as exe
Copy source: QTDIR/VER/mingw_64/plugins/platforms qwindows.dll Copy to: platforms subfolder of exe folder
Execute * .exe by double-clicking
Recommended Posts