(C++) How to cross-compile a Qt Creator project from Ubuntu to a windows executable: example 1: Hello World

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) How to cross-compile a Qt Creator project from Ubuntu to a windows executable: example 1: Hello World

 

STLQt
CreatorUbuntutoQt
CreatorWindows

 

This is example 1, and one of the solutions of answering the Qt FAQ How to cross-compile a Qt Creator project from Ubuntu to a windows executable?, thanks to [1].

 

 

 

 

 

Downloads

 

 

 

 

 

 

Project information

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: console application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

Qt project file

 


#------------------------------------------------- # # Project created by QtCreator 2010-09-23T19:13:58 # #------------------------------------------------- QT       += core QT       -= gui TARGET = CppQtCrosscompileToWindowsExample1 CONFIG   += console CONFIG   -= app_bundle TEMPLATE = app SOURCES += main.cpp

 

 

 

 

 

main.cpp

 


#include <iostream> int main() {   std::cout <<     "I am developed under Unbuntu, "     "and I will run under Windows\n"; }

 

 

 

 

 

Process

 

In an Ubuntu terminal, go to the folder containing main.cpp. Then type the following:

 


i586-mingw32msvc-g++ -o MyWin.exe main.cpp

 

This successfully creates a Windows executable called MyWin.exe. I have confirmed this to work on my old Windows computer.

 

 

 

 

 

References

 

 

 

 

 

[1] http://ubuntuforums.org/archive/index.php/t-626932.html