Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cross-compiling Qt for Linux on Windows



  • I'm trying to configure Qt Creator so that I can cross-compile Linux programs on Windows. I know that I can use a virtual machine, but my virtual machine is very slow so it would be nice if I don't have to run it every time I want to release an update for one of my programs.

    I already have a working Linux compiler and working Qt binaries for Linux. The Linux compiler is a small .exe file that I made that calls wsl.exe gcc with the right arguments, which runs the gcc compiler on a Windows subsystem for Linux. The Qt binaries for Linux are the binaries that came with Qt when I installed it on my Linux virtual machine, so I just copied the files from ~/Qt/5.15.12/gcc_64 on my virtual machine to C:\Qt\5.15.12\gcc_64 on Windows. I also created a C:\Qt\5.15.12\gcc_64\bin\qmake.exe file that calls wsl.exe /mnt/c/Qt/5.15.12/gcc_64/bin/qmake with the right arguments, which runs the Linux qmake on a Windows subsystem for Linux.

    So I have a working Linux compiler and working Qt binaries for Linux, but the problem is that I haven't managed to configure Qt Creator to use them. For the compiler, I went to Tools > Options > Compilers and added the Linux compiler manually, which Qt Creator seems to accept, but for the Qt binaries, I went to Tools > Options > Qt Versions and added C:\Qt\5.15.12\gcc_64\bin\qmake.exe, but Qt Creator gives me an error saying that "Qt version is not properly installed, please run make install". I assume it wants me to install it from the maintenance tool, but I can't since the maintenance tool for Windows doesn't have an option to install Linux binaries.

    alt text

    What I want to do is create a "Linux" kit which uses the Linux compiler and the Linux Qt binaries. How do I configure Qt Creator to do this?


  • Moderators

    @Donald-Duck said in Cross-compiling Qt for Linux on Windows:

    I also created a C:\Qt\5.15.12\gcc_64\bin\qmake.exe file that calls wsl.exe /mnt/c/Qt/5.15.12/gcc_64/bin/qmake with the right arguments, which runs the Linux qmake on a Windows subsystem for Linux.

    Out of curiosity, what happens when you call qmake.exe -query on your custom executable? This is what Qt Creator was checking when it told you "Qt version is not properly installed"

    I'm guessing that, at best, qmake.exe -query prints Linux paths (as seen from WSL). Linux paths are unusable to the Windows version of Qt Creator.



  • so I just copied the files from ~/Qt/5.15.12/gcc_64

    Narrator: It was at this point OP knew they messed up good.

    You can't do that. https://gcc.gnu.org/install/binaries.html
    I would assume there is near absolute zero support for trying to do what you are now. As everyone else just goes down the path of least resistance and uses what works out of the box. It's why we use tools/frameworks after all, so we don't get bogged down in the infrastructure and more on the project unique code.

    What you get out of the box (MinGW) is the best that works already and you already have it installed correctly because it's from the online installer and your screenshot looks good.
    Except for the bit where you've tried to manually jigger the GCC compiler onto Windows by just copying files - which Creator correctly says: no. That's not how you'd even begin to approach that so I would stop try that right there.

    MSVC | MinGW on windows builds.
    GCC on linux.

    I'd say you might:
    try getting another machine to build linux?
    use an online build server (if something like that exists) to generate your binaries?
    deal with it by continue to wait


  • Moderators

    @Donald-Duck said in Cross-compiling Qt for Linux on Windows:

    I also created a C:\Qt\5.15.12\gcc_64\bin\qmake.exe file that calls wsl.exe /mnt/c/Qt/5.15.12/gcc_64/bin/qmake with the right arguments, which runs the Linux qmake on a Windows subsystem for Linux.

    Out of curiosity, what happens when you call qmake.exe -query on your custom executable? This is what Qt Creator was checking when it told you "Qt version is not properly installed"

    I'm guessing that, at best, qmake.exe -query prints Linux paths (as seen from WSL). Linux paths are unusable to the Windows version of Qt Creator.



  • @JKSH said in Cross-compiling Qt for Linux on Windows:

    I'm guessing that, at best, qmake.exe -query prints Linux paths (as seen from WSL).

    Thanks. I changed the qmake.exe program so that it changes Linux paths in the output to Windows paths. Now Qt Creator is accepting it, so now I can use the kit.

    The problem now is that when I try to compile my programs using that kit, I get an error saying

    Could not start process "make" -f C:/Users/glind/AppData/Local/Temp/untitled2/build-untitled2/Makefile qmake_all
    

    I guess that's normal since the Make it's using is probably not the one for Linux, but how do I configure it to know which Make to use? I've found how to configure CMake in Qt Creator (and I've done that), but how do I configure Make? I could easily make a make.exe program which calls wsl.exe make with the right arguments, but how do I configure Qt Creator to use it?


  • Lifetime Qt Champion

    @Donald-Duck said in Cross-compiling Qt for Linux on Windows:

    but how do I configure it to know which Make to use?

    "Projects/Build & Run/Build/Build Steps/Make"



  • @jsulm Thanks, it worked.



  • @Donald-Duck said in Cross-compiling Qt for Linux on Windows:

    it worked.

    great. So please don't forget to mark your post as solved!


Log in to reply