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 7: any application, using universal binaries


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














Project information


Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: GUI application

Compiler: G++ 4.4.1

Libraries used:






Qt project file


# Project created by QtCreator 2010-09-25T09:43:28
QT       += core
QT       -= gui
LIBS += -L/usr/local/lib -lboost_filesystem
TARGET = CppQtCrosscompileToWindowsExample5
CONFIG   += console
CONFIG   -= app_bundle
SOURCES += main.cpp








///cross-compiling a console application with
///a library (that is: boost_filesystem).
#include <iostream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
//From http://www.richelbilderbeek.nl/CppGetFilesInFolder.htm
const std::vector<std::string> GetFilesInFolder(const std::string& folder)
  std::vector<std::string> v;

  const boost::filesystem::path my_folder
    = boost::filesystem::system_complete(

  if (!boost::filesystem::is_directory(my_folder)) return v;

  const boost::filesystem::directory_iterator j;
  for ( boost::filesystem::directory_iterator i(my_folder);
        i != j;
    if ( boost::filesystem::is_regular_file( i->status() ) )
      const std::string filename = i->path().filename();
      //const std::string full_filename = folder + "/" + filename;
  return v;
//From http://www.richelbilderbeek.nl/CppGetPath.htm
const std::string GetPath(const std::string& filename)
  return boost::filesystem::path(filename).parent_path().string();
int main(int, char* argv[])
  const std::vector<std::string> v = GetFilesInFolder(GetPath(argv[0]));
  std::cout << "Number of files: " << v.size() << '\n';








For this example, I use a console project that calls the Boost libraries. If you only need the STL, example 1: console application, no libaries shows an easy and successfull approach.


Additional qmake arguments can be supplied in the 'Projects -> Build Settings -> Build Steps -> qmake -> Additional arguments' edit.














[1] http://pepper.troll.no/s60prereleases/doc/qmake-platform-notes.html


Creating Universal Binaries

To create a universal binary for your application, you need to be using a version of Qt that has been configured with the -universal option.

The architectures to be supported in the binary are specified with the CONFIG variable. For example, the following assignment causes qmake to generate build rules to create a universal binary for both PowerPC and x86 architectures:

CONFIG += x86 ppc

Additionally, developers using a PowerPC-based platform need to set the QMAKE_MAC_SDK variable. This process is discussed in more detail in the deployment guide for Mac OS X.






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

Go back to Richel Bilderbeek's homepage.


Valid XHTML 1.0 Strict