HowTo Use OpenFOAM with QtCreator (solely IDE, Debug and Opt configurations)

From OpenFOAMWiki

1 Objective

This page provides instructions on how to set up a development environment on Qt Creator that meets the following requirements:

  • Qt Creator is launched from the window manager
  • The application is run and debugged within QtCreator
  • It is easy to switch from one build (or run) configuration (e.g., Debug) to another (e.g., Opt)


It consolidates information that can be found on HowTo Use OpenFOAM with QtCreator . For more options and instructions on how to configure QtCreator subject to other requirements, please refer to that page.

2 System configuration

These instructions were tested on a computer running:

  • Ubuntu 14.04
  • KDE 4.13.3
  • Qt Creator 2.0.1
  • OpenFOAM 2.3.1

3 Instructions

1) Append the following line to the end of your ~/.profile script (and edit it according to your installation)

source /home/user/OpenFOAM/OpenFOAM-2.3.1/etc/bashrc WM_COMPILE_OPTION=Debug

2) Create a project and write to the file <your_project>/Make/files

EXE = $(WM_OPTIONS)/bin/<name_of_your_executable>

3) Set two Build configurations and two Run configurations as shown in the snapshots below. In the examples, sandbox is just the name of my project and executable. Also replace %{buildDir} by the appropriate directory of the simulation you want to run, e.g., /home/user/OpenFOAM/user-2.3.1/run/tutorials/incompressible/icoFoam.

3.1) Build Configuration – Debug version (note that FOAM_SETTINGS=WM_COMPILE_Debug is redundant here):

Build Configuration – Debug version

3.2) Build Configuration – Opt version:

Build Configuration – Opt version

3.3) Run Configuration – Debug version:

Run Configuration – Debug version

3.4) Run Configuration – Opt version:

Run Configuration – Opt version

4 Explanations

Some explanations may be useful for those that are starting with OpenFOAM to understand the choices made in the above instructions:

1) The official OpenFOAM Foundation website suggests that you add

source /home/user/OpenFOAM/OpenFOAM-2.3.1/etc/bashrc WM_COMPILE_OPTION=Debug

to ~/.bash instead of ~/.profile. While ~/.bash is executed when a new terminal is opened, ~/.profile is executed when you log on to your window manager. Putting the source command in ~/.profile allows you to launch Qt Creator from the window manager while having the OpenFOAM environment variables already set.

2) When you want to use a different build or run configuration, environment variables relevant to OpenFOAM have to be reset to appropriate values before you run wmake, wclean or your own application. This can be done by calling foamExec and passing wmake, wclean or your own application as an argument to it. Before running the program indicated as an argument, foamExec it will call OpenFOAM-2.3.1/etc/bashrc, which sets the environment variables.

3) Without any argument OpenFOAM-2.3.1/etc/bashrc sets environment variables to default values. Different values can be set by passing arguments to this script, as in

OpenFOAM-2.3.1/etc/bashrc WM_COMPILE_OPTION=Debug

The arguments are "<variable>=<value>" separated by spaces.

4) When foamExec calls OpenFOAM-2.3.1/etc/bashrc, it uses as arguments the value of the FOAM_SETTINGS environment variable.

5) If one calls foamExec directly, it will be executed in a /bin/sh shell (because its first line is #!/bin/sh), which in Ubuntu 14.04, points to the dash shell. In dash shell, foamExec fails to pass arguments to OpenFOAM-2.3.1/etc/bashrc. This problem was reported on a foam-extended sourceforge page. However, if bash shell is used, this problem doesn't happen. That is why /bin/bash is the command on many of the snapshots above.

6) For "Run Configuration – Debug version" we cannot use foamExec to set the environment variables, because, if you ask Qt Creator to run it for debugging, it will try to debug foamExec. As there is not a practical way of changing the environment variables before launching the Debug version, we took WM_COMPILE_OPTION=Debug as a default. That is why this option is an argument to OpenFOAM-2.3.1/etc/bashrc.