DynamicLoader.hxx.in 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*=========================================================================
  2. Program: KWSys - Kitware System Library
  3. Module: $RCSfile$
  4. Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
  5. See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  8. PURPOSE. See the above copyright notices 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)
  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. class @KWSYS_NAMESPACE@_EXPORT DynamicLoader
  45. {
  46. public:
  47. // Ugly stuff for library handles
  48. // They are different on several different OS's
  49. #if defined(__hpux)
  50. typedef shl_t LibraryHandle;
  51. #elif defined(_WIN32)
  52. typedef HMODULE LibraryHandle;
  53. #elif defined(__APPLE__)
  54. #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
  55. typedef NSModule LibraryHandle;
  56. #else
  57. typedef void* LibraryHandle;
  58. #endif
  59. #elif defined(__BEOS__)
  60. typedef image_id LibraryHandle;
  61. #else
  62. typedef void* LibraryHandle;
  63. #endif
  64. // Return type from DynamicLoader::GetSymbolAddress.
  65. typedef void (*SymbolPointer)();
  66. DynamicLoader();
  67. ~DynamicLoader();
  68. /** Load a dynamic library into the current process.
  69. * The returned LibraryHandle can be used to access the symbols in the
  70. * library. */
  71. static LibraryHandle OpenLibrary(const char*);
  72. /** Attempt to detach a dynamic library from the
  73. * process. A value of true is returned if it is sucessful. */
  74. static int CloseLibrary(LibraryHandle);
  75. /** Find the address of the symbol in the given library. */
  76. static SymbolPointer GetSymbolAddress(LibraryHandle, const char*);
  77. /** Return the library prefix for the given architecture */
  78. static const char* LibPrefix();
  79. /** Return the library extension for the given architecture. */
  80. static const char* LibExtension();
  81. /** Return the last error produced from a calls made on this class. */
  82. static const char* LastError();
  83. }; // End Class: DynamicLoader
  84. } // namespace @KWSYS_NAMESPACE@
  85. #endif