OpenSceneGraph debug builds

OSG will not attempt to load debug plugins when built as debug. The assumption by the code is that the names for release and debug are the same.

However cmake gives you the default option of adding 'd'.

Normally mixing debug/release on Linux does not cause problems however on my system mixing causes random crashes.

The following are my changes to handle this.

damian@GP72-7RD:~/osgearth/OpenSceneGraph$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab2af99..782a785 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,7 @@ IF(MINGW)
     SET(OSG_PLUGIN_PREFIX "mingw_")
 ENDIF()

+set (CMAKE_CXX_STANDARD 11)

 # We want to build SONAMES shared librariess
 SET(OPENSCENEGRAPH_SONAMES TRUE)
diff --git a/src/osgDB/DynamicLibrary.cpp b/src/osgDB/DynamicLibrary.cpp
index e17dd20..24031b0 100644
--- a/src/osgDB/DynamicLibrary.cpp
+++ b/src/osgDB/DynamicLibrary.cpp
@@ -120,6 +120,25 @@ DynamicLibrary::HANDLE DynamicLibrary::getLibraryHandle( const std::string& libr
         localLibraryName = "./" + libraryName;
     else
         localLibraryName = libraryName;
+#if defined(_DEBUG)
+    size_t pos = localLibraryName.find( ".so" );
+    if ( pos != std::string::npos )
+    {
+      if ( localLibraryName.find( "d.so" ) == std::string::npos )
+      {
+        std::string debugLibraryName( localLibraryName );
+        debugLibraryName.insert( pos, "d" );
+        if ( fileExists( debugLibraryName ) )
+        {
+          localLibraryName = debugLibraryName;
+        }
+        else
+        {
+          OSG_WARN << "Warning: debug dynamic library '" << debugLibraryName << "' does not exists." << std::endl;
+        }
+      }
+    }
+#endif

     handle = dlopen( localLibraryName.c_str(), RTLD_LAZY | RTLD_GLOBAL);
     if( handle == NULL )



Comments