testDynamicLoader.cxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include "kwsysPrivate.h"
  11. #include KWSYS_HEADER(DynamicLoader.hxx)
  12. #include KWSYS_HEADER(ios/iostream)
  13. // Work-around CMake dependency scanning limitation. This must
  14. // duplicate the above list of headers.
  15. #if 0
  16. # include "DynamicLoader.hxx.in"
  17. # include "kwsys_ios_iostream.h.in"
  18. #endif
  19. int TestDynamicLoader(const char* libname, const char* symbol)
  20. {
  21. kwsys::LibHandle l = kwsys::DynamicLoader::OpenLibrary(libname);
  22. if( l )
  23. {
  24. kwsys_ios::cerr
  25. << kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
  26. return 1;
  27. }
  28. kwsys::DynamicLoaderFunction f =
  29. kwsys::DynamicLoader::GetSymbolAddress(l, symbol);
  30. if( f )
  31. {
  32. kwsys_ios::cerr
  33. << kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
  34. return 1;
  35. }
  36. int success = kwsys::DynamicLoader::CloseLibrary(l);
  37. if( success )
  38. {
  39. kwsys_ios::cerr
  40. << kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
  41. return 1;
  42. }
  43. return 0;
  44. }
  45. int main(int , char *[])
  46. {
  47. int res = TestDynamicLoader("foobar.lib", "foobar");
  48. return res;
  49. }