Compile OpenSceneGraph on Ubuntu vivid
Quickly compiling OSG to add it to my project...right...Must have been a while since I’ve encountered such a broken makefile.
#1 Set up the compiler flags.
Somehow CMake did not find much of my libraries, might be my fault, might be not. This is my full CMake string:
cmake . \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_FLAGS=-fPIC \ -DCMAKE_C_FLAGS=-fPIC \ -DOPENGL_gl_LIBRARY=/usr/lib/fglrx/libGL.so.1 \ -DX11_X11_LIB=/usr/lib/x86_64-linux-gnu/libX11.so \ -DJPEG_LIBRARY=/usr/lib/x86_64-linux-gnu/libjpeg.so \ -DPNG_LIBRARY=/usr/lib/x86_64-linux-gnu/libpng.so \ -DPNG_PNG_INCLUDE_DIR=/usr/include/libpng12 \ -DZLIB_LIBRARY=/lib/x86_64-linux-gnu/libz.so.1 \ -DTIFF_LIBRARY=/usr/lib/x86_64-linux-gnu/libtiff.so.5 \ -DTIFF_INCLUDE_DIR=/usr/include/x86_64-linux-gnu/tiff.h \ -DCURL_LIBRARY=/usr/lib/x86_64-linux-gnu/libcurl.so.4 \ -DCURL_INCLUDE_DIR=/usr/include/curl/ \ -DLIBXML2_LIBRARIES=/usr/lib/x86_64-linux-gnu/libixml.so.2 \ -DLIBXML2_INCLUDE_DIR=/usr/include/libxml2/libxml/ \ -DSDL_INCLUDE_DIR=/usr/include/SDL/ \ -DSDL_LIBRARY=/usr/lib/x86_64-linux-gnu/libSDL.so \ -DJASPER_LIBRARIES=/usr/lib/x86_64-linux-gnu/libjasper.so.1
Not all libraries are set, as I don’t have some of them. Important are the two -fPIC flags for the compiler. I did not set the compilers explicitly, because that causes CMake to “run twice” and in the second run it forgets about all my flags...Can I have a “configure && make && make install” please? *sigh* Okay this allows to start the compilation, but throws a lot of warnings, like this:
CMake Error: CMake can not determine linker language for target: osgdb_serializers_osg CMake Error: Cannot determine link language for target "osgdb_serializers_osg".
When building with this, it stops at about 52%, when trying to compile the “serializers”. Took me a while to figure out, it’s related to the warnings of CMake about “linker language not set” (see above).
#2 Fix CMakeList.txt
We need to tell CMake about which compiler to use for some of the modules. Because some modules don’t contain files and as a result CMake can’t guess which compiler to use(*). Problem is, this will break the compile process. So, to fix this, we need to tell CMake about the file types for these modules. Open up the main CMakeList.txt in the root directory, scroll pretty much to the end - #1245 for OSG 3.37 for me. There is this block:
SET(PKGCONFIG_FILES openscenegraph openscenegraph-osg openscenegraph-osgDB openscenegraph-osgFX openscenegraph-osgGA openscenegraph-osgParticle openscenegraph-osgSim openscenegraph-osgText openscenegraph-osgUtil openscenegraph-osgTerrain openscenegraph-osgManipulator openscenegraph-osgViewer openscenegraph-osgWidget openscenegraph-osgShadow openscenegraph-osgAnimation openscenegraph-osgVolume )
* for a NON EXISTING file, where there is nothing to compile, how silly is that?
After this block, add these lines to tell CMake about the language of the files mentioned in the warning when running CMake:
SET_TARGET_PROPERTIES(osgdb_serializers_osg PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgutil PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osganimation PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgfx PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgmanipulator PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgparticle PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgsim PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgshadow PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgga PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgterrain PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgtext PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgvolume PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgviewer PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_serializers_osgui PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osg PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgparticle PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osganimation PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgfx PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgsim PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgtext PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgviewer PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgshadow PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgterrain PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgvolume PROPERTIES LINKER_LANGUAGE CXX) SET_TARGET_PROPERTIES(osgdb_deprecated_osgwidget PROPERTIES LINKER_LANGUAGE CXX)
Run the CMake (with all the flags of course) command again, then make. Should hopefuly work. Good Luck!
#3 One problem left
Edith: Well, actually it still breaks at 98% for me.
Linking CXX executable ../../bin/osgviewer ../../lib/libosgViewer.so.3.3.7: undefined reference to `vtable for osgViewer::WoWVxDisplay' ../../lib/libosgViewer.so.3.3.7: undefined reference to `vtable for osgViewer::PanoramicSphericalDisplay' ../../lib/libosgViewer.so.3.3.7: undefined reference to `vtable for osgViewer::SingleScreen' ../../lib/libosgViewer.so.3.3.7: undefined reference to `vtable for osgViewer::SphericalDisplay' ../../lib/libosgViewer.so.3.3.7: undefined reference to `vtable for osgViewer::AcrossAllScreens' ../../lib/libosgViewer.so.3.3.7: undefined reference to `vtable for osgViewer::SingleWindow' collect2: error: ld returned 1 exit status applications/osgviewer/CMakeFiles/application_osgviewer.dir/build.make:95: recipe for target 'bin/osgviewer' failed make[2]: *** [bin/osgviewer] Error 1 CMakeFiles/Makefile2:7217: recipe for target 'applications/osgviewer/CMakeFiles/application_osgviewer.dir/all' failed make[1]: *** [applications/osgviewer/CMakeFiles/application_osgviewer.dir/all] Error 2 Makefile:117: recipe for target 'all' failed make: *** [all] Error 2
I hope I can figure this one out as well... So much wasted time... :|













