1

I have an Ubuntu build machine.

I wish to cross compile for Windows using MinGW which I have installed.

I am compiling QT apps (QT5 as it happens).

I am using CMake.

Native builds work fine out of the box, but cross compiling fails horribly because CMake cannot find the files used by FindPackage. To solve this I copied all the QT library files, header files, cmake files, and files under shared/qt5 from an MSYS2 MinGW/QT5 install (which works beautifully) into the relevant MinGW folder on my Ubuntu build machine. I also symbolically linked the native binaries for "qmake", "rcc", "moc", and "uic" into the correct location as the QT5 cmake files seemed to be looking for them. I suppose I should have edited the cmake files to look for the binaries with the target system prefix, and renamed the symlinks, but I was lazy.

CMake now succeeds, but when I then try to "make" my program I get the following error from "moc":

moc: could not find a Qt installation of ''

I guess that I am missing an environment variable or two.

Ideally I would like a solution which specifies some prebuilt Ubuntu packages that I can install to compile QT applications for Windows on Linux using MinGW, but frankly anything that works would be great.

AlastairG
  • 4,119
  • 5
  • 26
  • 41
  • Have you taken a look at [mxe](http://mxe.cc)? It should cover all of your use cases. – MateoConLechuga Sep 08 '17 at 15:05
  • MinGW, a contraction of "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications. You don't need MinGW on Linux because there you have normal ordinary GNU. – Alexander V Sep 09 '17 at 13:53
  • @AlexanderVX: You do need it if you want to build for Windows on Linux. In fact I cannot think of any other way to build for Windows on Linux. Please tell if you can think of one. – AlastairG Sep 10 '17 at 11:47
  • @MateoConLechuga: That looks interesting. I'm not sure how compatible it will be with our existing build environment though. I'll check it out when I get back to work. Thanks! – AlastairG Sep 10 '17 at 11:52
  • https://www.pcworld.com/article/2900497/how-to-run-windows-software-in-linux-everything-you-need-to-know.html – Alexander V Sep 10 '17 at 15:26
  • @AlexanderVX No, mingw is used for cross compiling on linux; as AlastairG already stated. (http://www.mingw.org/wiki/linuxcrossmingw) – MateoConLechuga Sep 10 '17 at 17:46
  • I then wonder of presence of all the necessary stuff for such big build project. IMHO not worth it. But I was telling about necessity to do so. Sometimes people do like to have more complicated ways. – Alexander V Sep 10 '17 at 18:50
  • @AlexanderVX: I don't understand you. It isn't a big build project. I want to automate a system to build the same software for Linux and Windows, and preferably both 32 bit and 64 bit Windows. I don't want to have to use two different machines and I don't want to have the complexity of trying to set up an automated system on Windows when, if I get the build system built, I can simply have a bash shell script run by a cron job and automatically sending emails with no effort at all. – AlastairG Sep 11 '17 at 07:46
  • I found my Linux build was also failing. As per the answer here (https://stackoverflow.com/questions/16607003/qmake-could-not-find-a-qt-installation-of) installing qt5-default solved that. However I now have the problem that my cross-compile environment will be finding my Linux QT libraries. – AlastairG Sep 11 '17 at 09:07
  • Use https://jenkins.io/ software to have the same build script and automation for different platforms. Windows 64 bit should be the host for Jenkins in your case for both bitnesses and Linux another host. Make sure to call correct qmake (and not from default Qt) to avoid the other problem. – Alexander V Sep 11 '17 at 14:38

1 Answers1

0

The answer turns out to be that I really need to compile my own custom version of Qt.

The error I got was because it turned out that the qmake binary wasn't a binary but was a symbolic link to something else. Fixing that allowed me to compile successfully, but all the dependencies are wrong and the resulting binary is not runnable. To solve this I need to compile Qt and all its dependencies myself :( As these include Harfbuzz with its circular dependencies this is not nice. My last attempt to compile and use such binaries resulted in an executable that simply crashed.

I really really wish that whoever provides the MinGW packages for Ubuntu would compile popular packages such as libicu, Qt, etc. etc. with MinGW and provide them as packages too.

Useful links:

https://marc.wäckerlin.ch/computer/cross-compile-on-ubuntu-linux-for-windows-using-mingw

https://github.com/mwaeckerlin/mingw

AlastairG
  • 4,119
  • 5
  • 26
  • 41