From 1cc1ddcacff981ec3c181aaeef55d7e8c1e6aef6 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 24 Oct 2011 21:31:38 +0100
Subject: [PATCH] ENH: dlOpen: check error message string

---
 src/OSspecific/POSIX/POSIX.C                             | 9 ++++++++-
 .../dictionary/functionEntries/codeStream/codeStream.C   | 6 +++---
 .../db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C    | 2 +-
 src/OpenFOAM/include/OSspecific.H                        | 5 +++--
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index e214e7eecab..7a16679511c 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -1161,7 +1161,7 @@ int Foam::system(const std::string& command)
 }
 
 
-void* Foam::dlOpen(const fileName& lib)
+void* Foam::dlOpen(const fileName& lib, const bool check)
 {
     if (POSIX::debug)
     {
@@ -1170,6 +1170,13 @@ void* Foam::dlOpen(const fileName& lib)
     }
     void* handle = ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
 
+    if (!handle && check)
+    {
+        WarningIn("dlOpen(const fileName&, const bool)")
+            << "dlopen error : " << ::dlerror()
+            << endl;
+    }
+
     if (POSIX::debug)
     {
         std::cout
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
index 7d78063d5e8..de0b87d9ea9 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
@@ -143,8 +143,8 @@ Foam::functionEntries::codeStream::getFunction
         }
         else
         {
-            // Uncached opening of libPath
-            lib = dlOpen(libPath);
+            // Uncached opening of libPath. Do not complain if cannot be loaded
+            lib = dlOpen(libPath, false);
         }
     }
 
@@ -226,7 +226,7 @@ Foam::functionEntries::codeStream::getFunction
         else
         {
             // Uncached opening of libPath
-            lib = dlOpen(libPath);
+            lib = dlOpen(libPath, true);
         }
     }
 
diff --git a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C
index f3628f20813..48bc178ac6a 100644
--- a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C
+++ b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C
@@ -78,7 +78,7 @@ bool Foam::dlLibraryTable::open
 {
     if (functionLibName.size())
     {
-        void* functionLibPtr = dlOpen(functionLibName);
+        void* functionLibPtr = dlOpen(functionLibName, verbose);
 
         if (debug)
         {
diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H
index d39a1c54cbb..14052f8a876 100644
--- a/src/OpenFOAM/include/OSspecific.H
+++ b/src/OpenFOAM/include/OSspecific.H
@@ -197,8 +197,9 @@ bool ping(const string&, const label timeOut=10);
 //- Execute the specified command
 int system(const std::string& command);
 
-//- open a shared library. Return handle to library
-void* dlOpen(const fileName& lib);
+//- open a shared library. Return handle to library. Print error message
+//  if library cannot be loaded (check = true)
+void* dlOpen(const fileName& lib, const bool check = true);
 
 //- Close a dlopened library using handle. Return true if successful
 bool dlClose(void*);
-- 
GitLab