How to compile OpenSceneGraph 2.x using MinGW/MSYS

This tutorial will explain how to compile OpenSceneGraph using MinGW with the source code from the SVN.

Last update: 11/03/2010
Notes:
Switched from MinGW nuwen.net to MinGW provided by Qt/Trolltech for better compatibility with Qt examples.

Requirements

Before following this tutorial, make sure that you have read the  the previous two tutorials:

The first one explains how to setup a MinGW/MSYS development environment, the second one explains how to install commonly used libraries in MinGW (most of them are required to build OpenSceneGraph).

Additional dependencies

FFmpeg

Qt 4.6.2

CMake

  • CMake (cmake-2.8.0-win32-x86.exe)
  • Install using default settings

Download the sourcecode from the OSG SVN

Preparing OpenSceneGraph (CMake)

  • Launch Cmake
  • Set “Where is the source code” to: C:/Projects/OpenSceneGraph/OpenSceneGraph-SVN
  • Set “Where to build the binaries” to: C:/Projects/OpenSceneGraph/OpenSceneGraph-Build
  • Click Configure
  • Choose MSYS Makefiles (Use default native compilers) and click on Finish
  • Enable “Simple View”
  • Set “ACTUAL_3DPARTY_DIR” to: C:/mingw
  • Enable BUILD_OSG_EXAMPLES
  • Set “CMAKE_BUILD_TYPE” to: Release
  • Set “CMAKE_INSTALL_PREFIX” to: C:/Projects/OpenSceneGraph/OpenSceneGraph-Bin
  • Click Configure
  • Enable “Grouped View”
  • Most of the libraries should’ve already been found, however there are a few you need to add manually
  • Set “TIFF_LIBRARY” to: C:/mingw/lib/libtiff.dll.a
  • Set “SDL_INCLUDE_DIR” to: C:/mingw/include/SDL
  • Set “SDL_LIBRARY” to: C:/mingw/lib/libSDL.dll.a
  • Set “QT_INCLUDE_DIR” to: C:/Qt/4.6.2/include
  • Set “QT_MOC_EXECUTABLE” to: C:/Qt/4.6.2/bin/moc.exe
  • Set “QT_QASSISTANTCLIENT_LIBRARY” to: C:/Qt/4.6.2/lib/libQtAssistantClient4.a
  • Set “QT_QMAKE_EXECUTABLE” to: C:/Qt/4.6.2/bin/qmake.exe
  • Set “QT_MAIN_LIBRARY” to: C:/Qt/4.6.2/lib/libqtmain.a
  • Set “QT_UIC_EXECUTABLE” to: C:/Qt/4.6.2/bin/uic.exe
  • Set “LIBXML2_INCLUDE_DIR” to: C:/mingw/include/libxml
  • Set “LIBXML2_LIBRARIES” to: C:/mingw/lib/libxml2.a
  • Set “GLUT_LIBRARY” to: C:/mingw/lib/libglut.dll.a
  • Set “GIFLIB_LIBRARY” to: C:/mingw/lib/libgif.a
  • Set “FREETYPE_INCLUDE_DIR” to: C:/mingw/include/freetype2
  • Set “FREETYPE_INCLUDE_DIR_freetype2″ to: C:/mingw/include/freetype2
  • Set “FREETYPE_INCLUDE_DIR_ft2build” to: C:/mingw/include/freetype2
  • Set “FFMPEG_ROOT” to: C:/Projects/3rdParty/ffmpeg
  • Set “SDLMAIN_LIBRARY” to: C:/mingw/lib/libSDLmain.a
  • Set “GLUT_glut_LIBRARY” to: C:/mingw/lib/libglut.dll.a
  • Click Configure
  • Click Configure
  • Click Generate

Building OpenSceneGraph

  • Open MSYS
  • Change your directory: cd /c/Projects/OpenSceneGraph/OpenSceneGraph-Build/
  • Type “make” and hit enter
  • Type “make install” and hit enter
  • Done! (OpenSceneGraph should now be installed in:
    C:\OpenSceneGraph\OpenSceneGraph-Bin)

Binaries (SVN)

Can’t be bothered to compile the source from scratch? Download the (release) binaries here:

Use 7zip to extract the content.

Additional resources

7 Comment

    Thanks for this Laurence!

    12 Jan 2010 | Reply

  1. Alvaro

    Thanks Laurence! Really useful How To :)

    12 Feb 2010 | Reply

  2. dashesy

    Thank you for the nice information! That is exactly what I was looking for.
    I was trying to use the pre-built libraries (.lib files for visual studio) with many linking problems.
    That would be nice if you add an entry to wiki:
    http://www.openscenegraph.org/projects/osg/wiki/Downloads
    for your MingWin binaries.
    The VS9 compiled libraries can not be directly used with MingWin I guess, I appreciate if you share any experience/solution regarding this.

    Thank you again!

    23 Feb 2010 | Reply

  3. @dashesy

    Unfortunately it is not possible to mix libraries from different compilers (Ok, there are some exception with C libraries, but that probably won’t apply for osg).

    Actually Jean-Sebastien Guay added a link here http://www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/Mingw

    Did you used the pre-built libraries from http://www.openscenegraph.org/projects/osg/wiki/Downloads/Dependencies ? The VisualStudio 9 (2008) SP1 files should work (be sure to update your compiler), if they don’t what error message do they show?

    23 Feb 2010 | Reply

  4. Just a small update:
    The section “Patching OpenSceneGraph” is not anymore required if you’re using the source code from the SVN (trunk). It has already been patched.

    Discussion: http://groups.google.com/group/osg-users/browse_thread/thread/73979e5d65302e93?tvc=2

    Bugfix: http://thread.gmane.org/gmane.comp.graphics.openscenegraph.cvs/6738

    23 Feb 2010 | Reply

  5. dashesy

    Thanks for the info!
    I was going to use dlltools to make some .a files from .lib files before I found your blog in the same link that you provided. I think similar to VS9 and VS8 there should be an official release for MingWin specially because many people like me use OSG with QT and are lazy not to build from the source themselves!

    When I use the release version from here:
    http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8.2/binaries/Windows/VisualStudio9/
    I get so many “undefined reference to” problems in the linking like (…/osg/OpenSceneGraph-2.8.2/include/osg/Referenced:147: undefined reference to `_imp___ZN11OpenThreads6AtomicppEv’ or ‘_imp___ZN3osg10ReferencedD2Ev’ or so many others)

    I tried both with “-L$${OSGHOME}/lib -l$${libname}” and also without “-l” option with $${libname}.lib, with no luck. I appreciate if you shed some light into this.

    However with .a files that you have provided the build works like a charm.
    I am using gcc 4.4.0 BTW

    23 Feb 2010 | Reply

  6. Hi dashesy,

    it would be nice if OSG would provide offical binaries build with MinGW (Qt/Trolltech are providing both VS and MinGW binaries for windows users)

    For the time being I will just post my own builds build with GCC 4.4.0 (from Trolltech).

    About your error, it is not possible to mix C++ libraries from different compilers.

    12 Mar 2010 | Reply

    Leave a reply