Search code examples
linuxhyperlinkfreetypeopenscenegraph

Error trying to link with osgText and freetype


I've already checked dozens of web pages and configurations about this. I'm desperate because I really need to use this feature and soon.

These are my settings:

  • Language: C++
  • Libraries: OpenSceneGraph (OSG) v3.2.0
  • OS: Xubuntu 14.04 (on a VMWare Player virtual machine)

I am compiling an example from the book "OpenSceneGraph 3.0 - Beginner's Guide", pages 297-299, regarding the use of Text on OSG, which requires an additional plug-in, freetype (http://www.freetype.org/), which is installed.

The example compiles correctly. I think I have all the required include files and libraries.

The problem comes in the link phase. It always gives me this error:

/usr/bin/ld: CMakeFiles/osg_demos.dir/osg_demos.cpp.o: undefined reference to symbol '_ZN7osgText12readFontFileERKSsPKN5osgDB7OptionsE'
//usr/lib/libosgText.so.99: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [osg_demos] Error 1
make[1]: *** [CMakeFiles/osg_demos.dir/all] Error 2
make: *** [all] Error 2

I checked that I have the files:

  • "/usr/lib/libosgText.so.99" which is a link to the actual lib file: "libosgText.so.3.2.0".
  • "/usr/lib/osgPlugins-3.2.0/osgdb_freetype.so" the external dependency of the osgText library.

I ran out of ideas. :(
Can someone help me?

My question stops here, but in case you want to check my files, please find them below.

The code responsible for this problem:

osgText::Text* createText( const osg::Vec3& pos, 
          const std::string& content, float size ) {
  osg::ref_ptr<osgText::Font> g_font = osgText::readFontFile("arial.ttf");
  osg::ref_ptr<osgText::Text> text = new osgText::Text;
  text->setFont( g_font.get() );
  text->setCharacterSize( size );
  text->setAxisAlignment( osgText::TextBase::XY_PLANE );
  text->setPosition( pos );
  text->setText( content );
  return text.release();
}

These are the Include files that I am using which are specific to osgText operations, apart from all the others that I already need on my project:

#include <osg/Camera>
#include <osgText/TextBase>
#include <osgText/Font>
#include <osgText/Text>

This is my "CMakeLists.txt" file:

cmake_minimum_required( VERSION 2.6 )
project( OSG_DEMOS )

find_package( OpenThreads )
find_package( osg )
find_package( osgDB )
find_package( osgGA )
find_package( osgUtil )
find_package( osgViewer )
find_package( osgText )         # Needed for demo: writeText()
find_package( osgShadow )       # Needed for demo: writeText()
find_package( osgParticle )     # Needed for demo: writeText()
find_package( osgFX )           # Needed for demo: writeText()
find_package(PCL 1.6 COMPONENTS)

set(CMAKE_CXX_FLAGS "-g -Wno-deprecated")

macro( config_project PROJNAME LIBNAME )
    include_directories( ${${LIBNAME}_INCLUDE_DIR} )
    target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARIES} )
endmacro()

add_executable(osg_demos osg_demos.cpp)

config_project(osg_demos OPENTHREADS )
config_project(osg_demos OSG )
config_project(osg_demos OSGDB )
config_project(osg_demos OSGGA )
config_project(osg_demos OSGUTIL )
config_project(osg_demos OSGVIEWER )
config_project(osg_demos osgText )
config_project(osg_demos osgShadow )
config_project(osg_demos osgParticle )
config_project(osg_demos osgFX )

Solution

  • The problem was on the "CMakeLists.txt" file. Apparently, the config_project macro requires all uppercase letters. I don't exactly understand why. To make the project link correctly, I switched to uppercase the reference to library name on the last four lines of that file, like:

    • config_project(osg_demos OSGTEXT )

    instead of:

    • config_project(osg_demos osgText )

    What a nightmare just because of this...