Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(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

 

llonesmiz
November 30th, 2007, 03:54 AM
You can install mingw this way:

sudo apt-get install mingw32

and then you can simply compile using i586-mingw32msvc-gcc instead of gcc:

i586-mingw32msvc-gcc -o test.exe test.c

You can also use i586-mingw32msvc-g++ and related tools.

If you use any libraries in your program, you will either need to crosscompile them too or just download the precompiled binaries for windows.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict