1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: DynamicLoader.hxx.in,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
14 #ifndef @KWSYS_NAMESPACE@_DynamicLoader_hxx
15 #define @KWSYS_NAMESPACE@_DynamicLoader_hxx
17 #include <@KWSYS_NAMESPACE@/Configure.h>
21 #elif defined(_WIN32) && !defined(__CYGWIN__)
23 #elif defined(__APPLE__)
24 #include <AvailabilityMacros.h>
25 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
26 #include <mach-o/dyld.h>
28 #elif defined(__BEOS__)
29 #include <be/kernel/image.h>
32 namespace @KWSYS_NAMESPACE@
34 /** \class DynamicLoader
35 * \brief Portable loading of dynamic libraries or dll's.
37 * DynamicLoader provides a portable interface to loading dynamic
38 * libraries or dll's into a process.
40 * Directory currently works with Windows, Apple, HP-UX and Unix (POSIX)
43 * \warning dlopen on *nix system works the following way:
44 * If filename contains a slash ("/"), then it is interpreted as a (relative
45 * or absolute) pathname. Otherwise, the dynamic linker searches for the
46 * library as follows : see ld.so(8) for further details):
47 * Whereas this distinction does not exist on Win32. Therefore ideally you
48 * should be doing full path to garantee to have a consistent way of dealing
49 * with dynamic loading of shared library.
51 * \warning the Cygwin implementation do not use the Win32 HMODULE. Put extra
52 * condition so that we can include the correct declaration (POSIX)
55 class @KWSYS_NAMESPACE@_EXPORT DynamicLoader
58 // Ugly stuff for library handles
59 // They are different on several different OS's
61 typedef shl_t LibraryHandle
;
62 #elif defined(_WIN32) && !defined(__CYGWIN__)
63 typedef HMODULE LibraryHandle
;
64 #elif defined(__APPLE__)
65 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
66 typedef NSModule LibraryHandle
;
68 typedef void* LibraryHandle
;
70 #elif defined(__BEOS__)
71 typedef image_id LibraryHandle
;
73 typedef void* LibraryHandle
;
76 // Return type from DynamicLoader::GetSymbolAddress.
77 typedef void (*SymbolPointer
)();
79 /** Load a dynamic library into the current process.
80 * The returned LibraryHandle can be used to access the symbols in the
82 static LibraryHandle
OpenLibrary(const char*);
84 /** Attempt to detach a dynamic library from the
85 * process. A value of true is returned if it is sucessful. */
86 static int CloseLibrary(LibraryHandle
);
88 /** Find the address of the symbol in the given library. */
89 static SymbolPointer
GetSymbolAddress(LibraryHandle
, const char*);
91 /** Return the library prefix for the given architecture */
92 static const char* LibPrefix();
94 /** Return the library extension for the given architecture. */
95 static const char* LibExtension();
97 /** Return the last error produced from a calls made on this class. */
98 static const char* LastError();
99 }; // End Class: DynamicLoader
101 } // namespace @KWSYS_NAMESPACE@