DynamicLoader.hxx.in 3.35 KB
Newer Older
1
2
3
/*============================================================================
  KWSys - Kitware System Library
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
12
13
14
15
16
#ifndef @KWSYS_NAMESPACE@_DynamicLoader_hxx
#define @KWSYS_NAMESPACE@_DynamicLoader_hxx

#include <@KWSYS_NAMESPACE@/Configure.h>

17
18
#if defined(__hpux)
  #include <dl.h>
19
#elif defined(_WIN32) && !defined(__CYGWIN__)
20
21
22
  #include <windows.h>
#elif defined(__APPLE__)
  #include <AvailabilityMacros.h>
23
  #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
24
25
    #include <mach-o/dyld.h>
  #endif
26
27
#elif defined(__BEOS__)
  #include <be/kernel/image.h>
28
29
#endif

30
31
namespace @KWSYS_NAMESPACE@
{
32
33
34
35
36
37
38
39
/** \class DynamicLoader
 * \brief Portable loading of dynamic libraries or dll's.
 *
 * DynamicLoader provides a portable interface to loading dynamic
 * libraries or dll's into a process.
 *
 * Directory currently works with Windows, Apple, HP-UX and Unix (POSIX)
 * operating systems
40
41
 *
 * \warning dlopen on *nix system works the following way:
42
43
44
45
46
47
 * If filename contains a slash ("/"), then it is interpreted as a (relative
 * or absolute) pathname.  Otherwise, the dynamic linker searches for the
 * library as follows : see ld.so(8) for further details):
 * Whereas this distinction does not exist on Win32. Therefore ideally you
 * should be doing full path to garantee to have a consistent way of dealing
 * with dynamic loading of shared library.
48
49
50
 *
 * \warning the Cygwin implementation do not use the Win32 HMODULE. Put extra
 * condition so that we can include the correct declaration (POSIX)
51
52
53
54
55
 */

class @KWSYS_NAMESPACE@_EXPORT DynamicLoader
{
public:
56
57
58
59
// Ugly stuff for library handles
// They are different on several different OS's
#if defined(__hpux)
  typedef shl_t LibraryHandle;
60
#elif defined(_WIN32) && !defined(__CYGWIN__)
61
62
  typedef HMODULE LibraryHandle;
#elif defined(__APPLE__)
63
  #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
64
65
66
67
    typedef NSModule LibraryHandle;
  #else
    typedef void* LibraryHandle;
  #endif
68
69
#elif defined(__BEOS__)
  typedef image_id LibraryHandle;
70
#else  // POSIX
71
72
73
74
75
76
  typedef void* LibraryHandle;
#endif

  // Return type from DynamicLoader::GetSymbolAddress.
  typedef void (*SymbolPointer)();

77
  /** Load a dynamic library into the current process.
78
   * The returned LibraryHandle can be used to access the symbols in the
79
   * library. */
80
  static LibraryHandle OpenLibrary(const char*);
81
82
83

  /** Attempt to detach a dynamic library from the
   * process.  A value of true is returned if it is sucessful. */
84
  static int CloseLibrary(LibraryHandle);
85
86

  /** Find the address of the symbol in the given library. */
87
  static SymbolPointer GetSymbolAddress(LibraryHandle, const char*);
88
89
90
91
92
93
94
95
96
97
98
99
100
101

  /** Return the library prefix for the given architecture */
  static const char* LibPrefix();

  /** Return the library extension for the given architecture. */
  static const char* LibExtension();

  /** Return the last error produced from a calls made on this class. */
  static const char* LastError();
}; // End Class: DynamicLoader

} // namespace @KWSYS_NAMESPACE@

#endif