DynamicLoader.hxx.in 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef @KWSYS_NAMESPACE@_DynamicLoader_hxx
  11. #define @KWSYS_NAMESPACE@_DynamicLoader_hxx
  12. #include <@KWSYS_NAMESPACE@/Configure.h>
  13. #if defined(__hpux)
  14. #include <dl.h>
  15. #elif defined(_WIN32) && !defined(__CYGWIN__)
  16. #include <windows.h>
  17. #elif defined(__APPLE__)
  18. #include <AvailabilityMacros.h>
  19. #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
  20. #include <mach-o/dyld.h>
  21. #endif
  22. #elif defined(__BEOS__)
  23. #include <be/kernel/image.h>
  24. #endif
  25. namespace @KWSYS_NAMESPACE@
  26. {
  27. /** \class DynamicLoader
  28. * \brief Portable loading of dynamic libraries or dll's.
  29. *
  30. * DynamicLoader provides a portable interface to loading dynamic
  31. * libraries or dll's into a process.
  32. *
  33. * Directory currently works with Windows, Apple, HP-UX and Unix (POSIX)
  34. * operating systems
  35. *
  36. * \warning dlopen on *nix system works the following way:
  37. * If filename contains a slash ("/"), then it is interpreted as a (relative
  38. * or absolute) pathname. Otherwise, the dynamic linker searches for the
  39. * library as follows : see ld.so(8) for further details):
  40. * Whereas this distinction does not exist on Win32. Therefore ideally you
  41. * should be doing full path to garantee to have a consistent way of dealing
  42. * with dynamic loading of shared library.
  43. *
  44. * \warning the Cygwin implementation do not use the Win32 HMODULE. Put extra
  45. * condition so that we can include the correct declaration (POSIX)
  46. */
  47. class @KWSYS_NAMESPACE@_EXPORT DynamicLoader
  48. {
  49. public:
  50. // Ugly stuff for library handles
  51. // They are different on several different OS's
  52. #if defined(__hpux)
  53. typedef shl_t LibraryHandle;
  54. #elif defined(_WIN32) && !defined(__CYGWIN__)
  55. typedef HMODULE LibraryHandle;
  56. #elif defined(__APPLE__)
  57. #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
  58. typedef NSModule LibraryHandle;
  59. #else
  60. typedef void* LibraryHandle;
  61. #endif
  62. #elif defined(__BEOS__)
  63. typedef image_id LibraryHandle;
  64. #else // POSIX
  65. typedef void* LibraryHandle;
  66. #endif
  67. // Return type from DynamicLoader::GetSymbolAddress.
  68. typedef void (*SymbolPointer)();
  69. /** Load a dynamic library into the current process.
  70. * The returned LibraryHandle can be used to access the symbols in the
  71. * library. */
  72. static LibraryHandle OpenLibrary(const char*);
  73. /** Attempt to detach a dynamic library from the
  74. * process. A value of true is returned if it is sucessful. */
  75. static int CloseLibrary(LibraryHandle);
  76. /** Find the address of the symbol in the given library. */
  77. static SymbolPointer GetSymbolAddress(LibraryHandle, const char*);
  78. /** Return the library prefix for the given architecture */
  79. static const char* LibPrefix();
  80. /** Return the library extension for the given architecture. */
  81. static const char* LibExtension();
  82. /** Return the last error produced from a calls made on this class. */
  83. static const char* LastError();
  84. }; // End Class: DynamicLoader
  85. } // namespace @KWSYS_NAMESPACE@
  86. #endif