Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross compiling Qt application for Windows on Linux with dynamic linking

To comply with Qt's LGPL license, an application using the Qt library must either make the source code available or link dynamically against Qt (if I got that correctly in this few words).

So I'd like to create a closed source application doing exactly that. Additionally, I'd like to develop on Linux (currently Xubuntu 12.04) using g++/MinGW with C++11 support to create windows binaries. I followed this helpful guide to accomplish the latter. But as the guide also states, statically linked executables are created.

Since I used MXE to automatically download and build the Qt library (version 5.0), I didn't have much of a chance to influence the process. So my question is, how do I create dynamically linked versions of the Qt library and respective applications?

like image 853
Ratatwisker Avatar asked Jan 28 '13 21:01

Ratatwisker


3 Answers

update

Now the preferable way to build dynamic versions of the libraries with MXE is specifying 'shared' option for the toolchain:

make MXE_TARGETS=i686-w64-mingw32.shared qt5

original

EDIT: I've created a git repository where I've gone through and made all the necessary changes to MXE to build a shared version of qtbase. It's available at https://github.com/jeremysalwen/mxe. To build, clone the repository and then run 'make qtbase'. I've left my original post below.

So I downloaded the mxe environment and it looks like the code used compile qt is help in src/qt.mk

The basic procedure is to match up this code with the standard directions for building qt. If you look inside qt.mk and qtbase.mk you'll see it's actually quite simple, and essentially just runs ./configure, make, and then installs the generated files. If you can look at this, you should be able to match up directions for building qt statically/dynamically and modify qt.mk so that it matches the dynamic directions.

In any case, I think I have found the issue. It looks like the difference is the "-static" flag when compiling qt. So if we simply remove the "-static" flag which is passed to ./configure in qt.mk and qtbase.mk, I would expect that mxe would then build a dynamic qt version. Of course you might need to change other things, but hopefully this is all you need to do.

like image 104
Jeremy Salwen Avatar answered Oct 28 '22 09:10

Jeremy Salwen


First you need to have wine setup.

sudo apt-get install wine

Then download Qt5 Windows MinGW SDK Run with wine

wget http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-mingw47_32-x86-offline.exe
wine qt-windows-opensource-5.0.1-mingw47_32-x86-offline.exe

Follow the wizard install Qt. Then

cd ~/.wine/drive_c/Qt/Qt5.0.1/Tools/QtCreator/bin
wine qtcreator.exe

I tried the examples in qtcreator, it compiles and runs well under linux, and when I copy the exe file to a windows machine with Qt set up, it also runs well.

Of course one drawback is that you are not feeling native using qtcreator and the compiler using wine. I don't know how much slower it is compared to native linux binary. But jom is available and you can utilize multiple cores to compile if your project is that big.

To use jom instead of make in qtcreator, modify here in qtcreator.

projects > Build & Run > Build > Build Steps > Make

replace with jom and add make arguments -j N where N is the core numbers you want to use.

like image 29
Min Lin Avatar answered Oct 28 '22 08:10

Min Lin


I've been stumbling through this recently and found some success with octave's fork of mxe. He went through the trouble to build qt with shared (.dll) library support which satisfied my needs. Here is a link to his post.

like image 26
Greg Pazo Avatar answered Oct 28 '22 09:10

Greg Pazo