简体   繁体   中英

How to cross-compile with MinGW on Linux for Windows?

I'm trying to compile a Qt5 application for Windows on Linux with MinGW.

I'm using Travis-CI to get continuous builds of two windows executables (win32, win64).

I've set up a build matrix, which contains the definition of the different MinGW dependencies. The before-install section defines the Qt, MinGW and gcc dependencies. The packages are fetched during install .

This is my .travis.yml :

language: cpp   
  matrix:
fast_finish: true
include:
  # cross-compile using mingw
  - compiler: ": w64"
    env: PLATFORM="mingw32" ARCH="x86_64" BITSIZE=64 HOST="x86_64"
  - compiler: ": w32"
    env: PLATFORM="mingw32" ARCH="x86" BITSIZE=32 HOST="i686"

install:
  - sudo add-apt-repository --yes ppa:beineri/opt-qt54                   # < Qt
  - sudo add-apt-repository --yes ppa:tobydox/mingw-x-precise            # < MinGW
  - sudo apt-get update -qq
  - uname -m
  - sudo apt-get install qt54base qt54imageformats qt54tools -y -qq
  - export QTDIR=/opt/qt54
  - export PATH=$QTDIR/bin:$PATH
  - export LD_LIBRARY_PATH=$QTDIR/lib/:$QTDIR/lib/`uname -m`-linux-gnu:$LD_LIBRARY_PATH
  - sudo apt-get install -y cloog-isl mingw32
  - if [ $BITSIZE == 32 ]; then sudo apt-get install -y mingw32-x-binutils mingw32-x-gcc mingw32-x-runtime; fi
  - if [ $BITSIZE == 64 ]; then sudo apt-get install -y mingw64-x-binutils mingw64-x-gcc mingw64-x-runtime; fi
  - export MINGW=/opt/mingw$BITSIZE
  - export PATH=$MINGW/bin:$PATH
  - export CC=$HOST-w64-mingw32-gcc
  - export CXX=$HOST-w64-mingw32-g++

script:
  - qmake -v
  - qmake wpnxm-servercontrolpanel.pro CONFIG+=release QMAKE_CC=$CC QMAKE_CXX=$CXX
  - gcc -v
  - gcc -dumpmachine
  - export CMAKE_OPTS="-DUSE_WERROR=ON"
  - make -j2 VERBOSE=1

The build fails.

The output of make contains

 i686-w64-mingw32-g++ -c -pipe -O2 -std=c++0x -D_REENTRANT -Wall -W -fPIE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/opt/qt54/mkspecs/linux-g++ -I. -I/opt/qt54/include -I/opt/qt54/include/QtWidgets -I/opt/qt54/include/QtGui -I/opt/qt54/include/QtNetwork -I/opt/qt54/include/QtCore -I. -I. -o mainwindow.o src/mainwindow.cpp
src/mainwindow.cpp:1:0: warning: -fPIC ignored for target (all code is position independent)
 /*
 ^
src/mainwindow.cpp:41:21: fatal error: QCheckbox: No such file or directory
 #include <QCheckbox>
                     ^
compilation terminated.

Found out: it's QCheck B ox.

I'm not sure, if i fetch the right version of Qt5.

Which changes are needed to build the executables?

First of all, make sure you have the mingw32 , mingw32-binutils and mingw32-runtime packages installed. The runtime package contains all the common Windows headers you'll need for cross-compiling, like the missing "windows.h".

Also be aware that you're trying to cross-compile using a Linux version of the Qt library. This will fail during the linking stage. You need mingw32 versions (.DLLs) of all the dependencies you require.

Since Travis don't offer mingw32 Qt packages yet, you will have to install them from a third party source (see http://docs.travis-ci.com/user/installing-dependencies/ ) like https://launchpad.net/~tobydox/+ppa-packages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM