Qt World Summit: Submit your Presentation

[Solved] Build for a Linux Target (Ubuntu) from my windows QT SDK

  • Hi All,

    I am sure this must have been asked before, but I could not find a topic for it.

    I have installed QT 5.0.2 SDK (QT Creator 2.7.0, mingw47, etc.) on my windows box. I have a project that runs nicely on the windows platform (in this case its windows XP sp3).

    However our plan was to get this project working on windows and then migrate to Ubuntu. I am quite happy to install QT on Ubuntu and will do at some point, but I get the impression that we can cross-compile from windows platform to Linux target files with the QT environment (from what I have read here and there). Then I guess we could run the produced target files in Ubuntu...

    Can anyone confirm this is possible? and if so point me in the direction of some docs/guides that can help? (or even some advice)

    Thanks :)

  • Lifetime Qt Champion


    AFAIK (but that is old knowledge) you can achieve this using cygwin. However I would recommend to build directly in a linux environment so you can directly test that your application is working properly (also you gain some additional tools like valgrind for example)

    As a side note, it's Qt, QT is for Apple's QuickTime :)

    Hope it helps

  • Hi SGaist,

    Yes, I think you are right, I will probably just wast my time trying to compile for linux on a windows box...may as well just take the plunge and run it directly on Ubuntu :o

  • From my experience it works best to have at least one developer using each of the target platforms for his/her daily work (if you have enough developers that is). That way you catch incompatibilities early. You will have incompatibilities, be it due to platform code sneaking in or maybe just due to different compilers interpreting your code differently:-) Someone working on a platform all the time tends to also notice small issues that are not obvious right away.

    If you are alone switching platforms every couple of days also works.

  • Hi Tobias, sorry about my slow reply, I have been away.

    Thanks for sharing your thoughts, this all looks like very sound practises to me. I do work on my own at the moment, but I have both win and linux PCs and can swap between them.

    One thing I did find that is worth noting is that the C++11 compiler for QT 5.0.2 on the windows version seems more advanced then the C++11 compiler (which I am not sure has any C++11 features) on the linux PC, so I have decided to remove the C++11 features from my current project to keep things simpler (in my case only minor changes).

  • Yes, C++11 support (still) differs a lot between compilers and compiler versions. The compiler we ship in the mingw-flavor for windows is gcc 4.7 based.

    So a GCC 4.7 on Linux should be pretty similar in the functionality it supports. Which compiler/version are you using on Linux?

  • I have gcc/g++ version 4.4.3 (shipped with QT 5.0.2 as default). So it looks like you are right, they are using slightly different versions, I did not expect that initially.

    I think I will wait until both Lin/Win versions fully support C++11 until I start to use those features. To be honest the need to use them is no so great!

    Thanks :)

  • Qt does not ship any compiler on linux.

    We just use the one that is provided by your distribution of choice. They are really easy to install and (most of the time) produce code that is compatible to all the other Linux-compilers out there.

  • ohh! .... lol, that will explain that then. I had, wrongly, assumed it was part of the installation like it is for windows :o

    Thanks :)

  • Ok, I think I have 95% cracked it :)

    In my .pro file it appears there is a lot of things you can do. So I have currently have the following:

    BUILD_DIR = ../_out
    QMAKE_CXXFLAGS += -recursive
    QMAKE_POST_LINK += cp rpe.xml $$BUILD_DIR;
    QMAKE_POST_LINK += cp rpeSim.xml $$BUILD_DIR;
    win* {
    message (Building for windows target)
    QMAKE_CXXFLAGS += -std=gnu++11
    linux* {
    message (Building for linux target)
    #QMAKE_CXXFLAGS += -std=gnu++11

    Basically it makes all of the output go into the folder "../_out" relative to the project location. This works all except for the make files and object_script files (about 6 in total). This I can probably live with, though if there is a way to move those as well, that would be nice! (could add another few QMAKE_POST_LINK lines I suppose.

    One thing that I have not yet cracked is "run" project options. In QT creator under Projects-->Run You have:
    Executable: path\executable_file
    Arguments: ...
    Working Directory: ....../_out

    In arguemnts I specify "2> file.log"
    So that when the executable runs the stderror is re-directed to a log file. If I could specify this somehow in the .pro file then I would finally be free of needing anything from the .pro.user file :)

    So there it is... any thoughts on that?

Log in to reply