- wxString lib_name = name;
- wxNode *node;
- wxLibrary *lib;
- wxClassInfo *old_sm_first;
-
- if ( (node = m_loaded.Find(name.GetData())) )
- return ((wxLibrary *)node->Data());
-
- // If DLL shares data, this is necessary.
- old_sm_first = wxClassInfo::sm_first;
- wxClassInfo::sm_first = NULL;
-
-#if defined(__UNIX__) || defined(__unix__)
- lib_name.Prepend("./lib");
- lib_name += ".so";
-
- printf("lib_name = %s\n", WXSTRINGCAST lib_name);
-
- void *handle = dlopen(WXSTRINGCAST lib_name, RTLD_LAZY);
-
- printf("error = %s\n", dlerror());
-
- if (!handle)
- return NULL;
-#elif defined(__WINDOWS__)
- lib_name += ".dll";
-
-#ifdef UNICODE
- HMODULE handle = LoadLibraryW(lib_name);
-#else
- HMODULE handle = LoadLibraryA(lib_name);
-#endif
- if (!handle)
- return NULL;
-#else
- return NULL;
-#endif
-
- lib = new wxLibrary((void *)handle);
-
- wxClassInfo::sm_first = old_sm_first;
-
- m_loaded.Append(name.GetData(), lib);
- return lib;
+ wxNode *node;
+ wxLibrary *lib;
+ wxClassInfo *old_sm_first;
+
+ if ( (node = m_loaded.Find(name.GetData())) )
+ return ((wxLibrary *)node->Data());
+
+ // If DLL shares data, this is necessary.
+ old_sm_first = wxClassInfo::sm_first;
+ wxClassInfo::sm_first = NULL;
+
+ wxString lib_name = ConstructLibraryName(name);
+
+#if defined(__UNIX__)
+ // found the first file in LD_LIBRARY_PATH with this name
+ wxString libPath("/lib:/usr/lib"); // system path first
+ const char *envLibPath = getenv("LD_LIBRARY_PATH");
+ if ( envLibPath )
+ libPath << ':' << envLibPath;
+ wxStringTokenizer tokenizer(libPath, ':');
+ while ( tokenizer.HasMoreToken() )
+ {
+ wxString fullname(tokenizer.NextToken());
+
+ fullname << '/' << lib_name;
+ if ( wxFileExists(fullname) )
+ {
+ lib_name = fullname;
+
+ // found the library
+ break;
+ }
+ }
+ //else: not found in the path, leave the name as is (secutiry risk?)
+
+#endif // __UNIX__
+
+ wxDllType handle;
+
+#if defined(__WXMAC__)
+ FSSpec myFSSpec ;
+ Ptr myMainAddr ;
+ Str255 myErrName ;
+
+ wxMacPathToFSSpec( lib_name , &myFSSpec ) ;
+ if (GetDiskFragment( &myFSSpec , 0 , kCFragGoesToEOF , "\p" , kPrivateCFragCopy , &handle , &myMainAddr ,
+ myErrName ) != noErr )
+ {
+ p2cstr( myErrName ) ;
+ wxASSERT_MSG( 1 , (char*)myErrName ) ;
+ return NULL ;
+ }
+#else // !Mac
+ handle = wxDllOpen(lib_name);
+#endif // OS
+
+ if ( !handle )
+ {
+ wxLogSysError(_("Failed to load shared library '%s'"),
+ lib_name.c_str());
+
+ return NULL;
+ }
+
+ lib = new wxLibrary(handle);
+
+ wxClassInfo::sm_first = old_sm_first;
+
+ m_loaded.Append(name.GetData(), lib);
+
+ return lib;