Building OsgEarth on Ubuntu 14.04

I already had QT 5.5.1 with GCC 4.7.3 (and probably some libraries, including libcurl4-gnutls-dev, libgdal-dev, glut, that are installed, but not built) on my machine, so I built OSG with the following commands (I am not sure that it makes a sense to clone recursively, but making with ‘CMAKE_BUILD_TYPE=Debug’ can be better than with ‘debug’ or ‘DEBUG’, because CMAKE does case-sensitive compare. We can build osgEarth 2.8 against OSG 3.4 or osgEarth master branch against OSG 3.4 or newer..):

cd ~
mkdir examples
cd examples
mkdir install
git clone --recursive
git tag
git reset --hard OpenSceneGraph-3.4.0
mkdir -p build/osg
cd build/osg
cmake ../../OpenSceneGraph/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install
make -j3 install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/dmitry/examples/install/lib64

The last command shows OSG version. Then I easily built OsgEarth with the similar steps:

cd ~/examples
git clone --recursive
git tag
git reset --hard osgearth-2.8
cd build
mkdir osgearth
cd osgearth
cmake ../../osgearth/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install
make -j3
make install

After that I built my application:

export PKG_CONFIG_PATH=/home/dmitry/examples/install/lib64/pkgconfig:$PKG_CONFIG_PATH
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/build

There are also the following environment variables in my ~./bashrc

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/opt/lib/pkgconfig:$HOME/lib_build/qwt/lib/pkgconfig:/home/user/opt/lib64/pkgconfig
export LD_LIBRARY_PATH=$HOME/opt/lib/x86_64-linux-gnu:$HOME/lib_build/qwt/lib:$HOME/build/lib:$LD_LIBRARY_PATH:/home/user/opt/lib64/

It is interesting that the total size of the source code (*.h, *.cpp) in OSG and OsgEarth is 18981452 + 23346192 = 42327644 bytes = 40.366 MB. Before in some project we used OpenSceneGraph-3.3.9 with osgearth-2.7.

Other useful GIT commands for working with tags:

git describe --tags
git reset --hard origin/master

Starting the sample with grid on the Earth:

./osgearth_graticuled ~/.../

There are some options to compile OSG with different versions of OpenGL in the CMakeFileLists.txt, for example there is a variable that defines whether OSG uses OpenGL display lists or not:

SET(OPENGL_PROFILE "GL2" CACHE STRING "OpenGL Profile to use, choose from GL1, GL2, GL3, GLES1, GLES2, GLES3")
    OPTION(OSG_GL_DISPLAYLISTS_AVAILABLE "Set to OFF to disable use of OpenGL display lists." OFF)

I successfully tried to enable OpenGL3 with the following CMake parameters (by default, GL2 is set):

cmake ../../OpenSceneGraph/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install -DOPENGL_PROFILE=GL3

It generates include file ‘/home/dmitry/examples/build/osg/include/osg/GL’ with the following content:

#include <GL3/gl3.h>

But, probably, on Ubuntu, for example, GL3/gl3.h should be replaced with GL/gl.h, at least the following command shows that it exists only in OpenGLES:

dpkg -S gl3.h
libgles2-mesa-dev: /usr/include/GLES3/gl3.h

This file appeared on my machine after I installed this mesa package:

sudo apt-get install libgles2-mesa-dev

See also:

With the following option OsgEarth 2.8 builds its QT module and samples:

cmake ../../osgearth/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install -DOSGEARTH_USE_QT=ON

OsgEarth 2.7 builds its QT modules and examples by default, but its examples ‘osgearth_qt_windowsd‘ and ‘osgearth_qt_simpled‘ crash with message ‘Cannot make QOpenGLContext current in a different thread’.

OpenSceneGraph-3.5.6 does not have osgQT module anymore in its source directory, so OsgEarth QT module cannot we built against it.

Tag OpenSceneGraph-3.4.1-rc1 was set on 2017-07-28, but tag OpenSceneGraph-3.4.0 was set on 2015-08-12, so the difference in time is about two years:

$ cd ../osgearth/
$ git log --tags --simplify-by-decoration --pretty="format:%ai %d" | grep 2.7
2015-07-30 12:13:07 -0400  (tag: osgearth-2.7, master)
2015-07-17 15:17:25 -0400  (tag: osgearth-2.7rc2)
2015-07-14 09:39:50 -0400  (tag: osgearth-2.7rc1)
$ git log --tags --simplify-by-decoration --pretty="format:%ai %d" | grep 2.8
2016-09-15 10:19:21 -0400  (tag: osgearth-2.8)
$ cd ../OpenSceneGraph/
$ git log --tags --simplify-by-decoration --pretty="format:%ai %d" | grep 3.4.0
2015-08-12 11:13:17 +0000  (tag: OpenSceneGraph-3.4.0)
2015-08-09 10:21:25 +0000  (tag: OpenSceneGraph-3.4.0-rc11)
2015-08-06 15:14:40 +0000  (tag: OpenSceneGraph-3.4.0-rc10)
2015-08-03 19:38:50 +0000  (tag: OpenSceneGraph-3.4.0-rc9)
2015-07-31 15:13:34 +0000  (tag: OpenSceneGraph-3.4.0-rc8)
2015-07-23 21:34:14 +0000  (tag: OpenSceneGraph-3.4.0-rc7)
2015-07-22 14:57:32 +0000  (tag: OpenSceneGraph-3.4.0-rc6)
2015-07-20 07:53:51 +0000  (tag: OpenSceneGraph-3.4.0-rc5)
2015-07-17 10:17:14 +0000  (tag: OpenSceneGraph-3.4.0-rc4)
2015-07-14 16:55:44 +0000  (tag: OpenSceneGraph-3.4.0-rc3)
2015-07-14 16:38:44 +0000  (tag: OpenSceneGraph-3.4.0-rc2)
2015-07-03 06:50:36 +0000  (tag: OpenSceneGraph-3.4.0-rc1)
$ git log --tags --simplify-by-decoration --pretty="format:%ai %d" | grep 3.4.1
2017-07-28 17:57:02 +0100  (HEAD, tag: OpenSceneGraph-3.4.1-rc1, text-bug)

All the OpenSceneGraph-3.4.XXX releases are in the separate branch:

git show --summary OpenSceneGraph-3.4.1-rc1
git log remotes/origin/OpenSceneGraph-3.4

QT header file include/QtCore/qglobal.h contains the following condition that can cause compiler error with GCC 5.2:

#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && \
    (!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >= 500))
#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
         "Compile your code with -fPIC (-fPIE is not enough)."

Theoretically, the compiler option can be set in CMake command line like this:


1 Response to Building OsgEarth on Ubuntu 14.04

  1. dmitriano on September 5, 2017 at 3:44 PM:

    Deadlock while adding a model layer to the map node:
    We load a model layer from a shape file and add it to the map:

    osg::ref_ptr model_layer = createModelLayer(filename, …);


    the deadlock occurs in addModelLayer when mutex _**clampableMutex** is locked twice (recursively) with the following call stack (in file osgearth/src/osgEarthFeatures/FeatureModelGraph.cpp):

    void FeatureModelGraph::checkForGlobalStyles( const Style& style )
    OpenThreads::ScopedLock lk(_clampableMutex);

    void FeatureModelGraph::redraw()
    OpenThreads::ScopedLock lk(_clampableMutex);

    we use OSG 3.4/OsgEarth 2.8, this does not occur the latest OsgEarth sources from its master branch.

Leave a Reply

Your email address will not be published. Required fields are marked *