Index: trunk/SophyaLib/SysTools/cxxcmplnk.cc
===================================================================
--- trunk/SophyaLib/SysTools/cxxcmplnk.cc	(revision 2495)
+++ trunk/SophyaLib/SysTools/cxxcmplnk.cc	(revision 2496)
@@ -101,6 +101,6 @@
   linkCmd = compCmd;
 #else
-  linkCmd = "cc -bundle -flat_namespace -undefined suppress ";
-  linkOptions = "-L/usr/lib/gcc/darwin/default -lstdc++ -lcc_dynamic -lpthread ";
+  linkCmd = "c++ -bundle ";
+  linkOptions = "-lSystem -lm";
 #endif
 
Index: trunk/SophyaLib/SysTools/pdlmgr.cc
===================================================================
--- trunk/SophyaLib/SysTools/pdlmgr.cc	(revision 2495)
+++ trunk/SophyaLib/SysTools/pdlmgr.cc	(revision 2496)
@@ -172,5 +172,6 @@
   cmd = "ld -b -o " + fnameso + " " + fnameobj + " -lm -lc";
 #elif defined(Darwin)
-  cmd = "cc -bundle -flat_namespace -undefined suppress -o " + fnameso + " " + fnameobj + " -lm  -lcc_dynamic -lSystem ";
+  // cmd = "cc -bundle -flat_namespace -undefined suppress -o " + fnameso + " " + fnameobj + " -lm  -lcc_dynamic -lSystem ";
+  cmd = "cc -bundle -o " + fnameso + " " + fnameobj + " -lSystem -lm";
 #else 
   cmd = "ld -o " + fnameso + " " + fnameobj + " -lm -lc";
@@ -195,7 +196,5 @@
 PDynLinkMgr::PDynLinkMgr(string& soname, bool cp)
 {
-#ifndef Darwin
-dlhandle = NULL;
-#endif
+dylok = false;
 soName = "";
 
@@ -230,18 +229,42 @@
 soName = fnameso;
 
+string sdylerr;
 #if defined(HPUX)
-dlhandle = NULL;
 cerr << "PDynLinkMgr::PDynLinkMgr() Not yet available on HP-UX " << endl;
 return;
-#else
+#elif defined(Darwin)
+NSObjectFileImageReturnCode nsrc = NSCreateObjectFileImageFromFile(fnameso.c_str(), &nsobjfile);
+if (nsrc == NSObjectFileImageSuccess) {
+  nsmod = NSLinkModule(nsobjfile, fnameso.c_str(),
+		       NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_PRIVATE | 
+		       NSLINKMODULE_OPTION_RETURN_ON_ERROR);
+  // The second argument of NSLinkModule is the module name
+  // We might associate later a name for the module in the PDynLinkMgr object
+  if (nsmod != NULL) dylok = true;
+  else cerr << "PDynLinkMgr::PDynLinkMgr()/ Error from NSLinkModule ... " << endl;
+}
+else { 
+  cerr << "PDynLinkMgr::PDynLinkMgr()/ Error from NSCreateObjectFileImageFromFile ... " << endl;
+  if (nsrc == NSObjectFileImageFailure) cerr << " ErrCode= NSObjectFileImageFailure " << endl;
+  else if (nsrc == NSObjectFileImageInappropriateFile) cerr << " ErrCode= NSObjectFileImageInappropriateFile" << endl;
+  else if (nsrc == NSObjectFileImageArch ) cerr << " ErrCode= NSObjectFileImageArch" << endl;
+  else if (nsrc == NSObjectFileImageFormat) cerr << " ErrCode= NSObjectFileImageFormat" << endl;
+  else if (nsrc == NSObjectFileImageAccess) cerr << " ErrCode= NSObjectFileImageAccess" << endl;
+}
+#else
+dlhandle = NULL;
 dlhandle =  dlopen(fnameso.c_str(), RTLD_NOW);
-if (dlhandle == NULL) { 
+if (dlhandle != NULL) dylok = true;
+else { 
+  sdylerr = "Loader Error (dlerror()):";
+  sdylerr += dlerror();
+#endif
+
+if (!dylok)  {
   cerr << "PDynLinkMgr::PDynLinkMgr(): Error opening SO " << fnameso 
        << " (" << soname << ")" << endl; 
-  string sn = dlerror();
-  cerr << "Loader Error (dlerror()) :" << sn << endl;
+  if (sdylerr.length() > 0) cerr << sdylerr;
   return; 
   }
-#endif
 }
 
@@ -253,12 +276,19 @@
 #if defined(HPUX)
 cerr << "PDynLinkMgr::~PDynLinkMgr() Not yet available on HP-UX " << endl;
-return;
-#else
-if (dlhandle) dlclose(dlhandle);    dlhandle = NULL;
+// return;
+#elif defined(Darwin)
+if (dylok) { 
+  if (nsmod != NULL)  NSUnLinkModule(nsmod, NSUNLINKMODULE_OPTION_NONE);
+  NSDestroyObjectFileImage(nsobjfile);
+  }
+#else
+if (dylok) {
+  if (dlhandle) dlclose(dlhandle);    dlhandle = NULL;
+  }
+#endif
 if (copy) {
   string cmd = "rm -f " + soName;
   system(cmd.c_str());
   }
-#endif
 }
 
@@ -269,19 +299,25 @@
 {
 DlFunction f = NULL;
+if (!dylok) {
+  cerr << "PDynLinkMgr::GetFunction() Error:sharedobjet/dynamic library not open -> f=NULL" << endl;
+  return f;
+}
 #if defined(HPUX)
 cerr << "PDynLinkMgr::GetFunction() Not yet available on HP-UX " << endl;
 return f;
-#else 
+#endif
 #if defined(Darwin)
 string funame = "_" + funcname;
+NSSymbol nsf = NSLookupSymbolInModule(nsmod, funame.c_str());
+f = (DlFunction)NSAddressOfSymbol(nsf);
 #else 
 string const & funame = funcname;
-#endif
 if (dlhandle != NULL)  
   f = (DlFunction)dlsym(dlhandle, funame.c_str());
+#endif
+
 if (f == NULL) cerr << "PDynLinkMgr::GetFunction(): Error linking " << funcname << endl;
 return(f);
-#endif
-}
-
-
+}
+
+
Index: trunk/SophyaLib/SysTools/pdlmgr.h
===================================================================
--- trunk/SophyaLib/SysTools/pdlmgr.h	(revision 2495)
+++ trunk/SophyaLib/SysTools/pdlmgr.h	(revision 2496)
@@ -13,5 +13,5 @@
 #include <dl.h>
 #elif defined(Darwin)
-#include </sw/include/dlfcn.h>
+#include <mach-o/dyld.h>
 #else
 #include <dlfcn.h>
@@ -35,4 +35,8 @@
 
   virtual DlFunction	GetFunction(string const & funcname);              
+  inline  DlFunction	GetFunction(const char * funcname) 
+    { string fname = funcname;   return GetFunction(fname); }            
+
+  inline  string        GetName() const { return soName; }
 
 protected :
@@ -43,7 +47,11 @@
 #if defined(HPUX)
   shl_t dlhandle;
+#elif defined(Darwin)
+  NSObjectFileImage nsobjfile;
+  NSModule nsmod;
 #else 
   void * dlhandle;
 #endif
+  bool dylok;
   string soName;
   bool copy;
Index: trunk/SophyaLib/SysTools/zthread.h
===================================================================
--- trunk/SophyaLib/SysTools/zthread.h	(revision 2495)
+++ trunk/SophyaLib/SysTools/zthread.h	(revision 2496)
@@ -98,7 +98,7 @@
   { 
     if (_mtx) { 
-      _mtx->unlock(); 
       if (_sigbr == 1) _mtx->signal(); 
       else  if (_sigbr == 2) _mtx->broadcast(); 
+      _mtx->unlock(); 
     }
   }
