Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

dlloader.cpp

Example: dlloader.cpp application


#include <exception>
#include <iostream>
#include <cxxtools/dlloader.h>
#include <cxxtools/loginit.h>

typedef double (*function_type)(double);

// to run the program you may have to set LTDL_LIBRARY_PATH
// to the path of libm.so

int main(int argc, char* argv[])
{
  try
  {
    log_init();

    if (argc == 1)
    {
      std::cout << "load libm.so" << std::endl;
      cxxtools::dl::Library lib("m");

      std::cout << "sym cos" << std::endl;
      function_type cosine = (function_type)(lib["cos"]);

      std::cout << "call cos" << std::endl;
      std::cout << "cos(2.0) = " << cosine(2.0) << std::endl;
    }
    else
    {
      std::cout << "load " << argv[1] << std::endl;
      cxxtools::dl::Library lib(argv[1]);

      for (int a = 2; argv[a]; ++a)
      {
        std::cout << "sym " << argv[a] << std::endl;
        cxxtools::dl::Symbol sym = lib.getSymbol(argv[a]);
        std::cout << " => " << static_cast<void*>(sym) << std::endl;
      }
    }
  }
  catch (const std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }
}

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6