tutorial2.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
  2. // Copyright 2015-2019 Antony Polukhin.
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include "../b2_workarounds.hpp"
  8. //[callplugcpp_tutorial2
  9. #include <boost/dll/import.hpp> // for import_alias
  10. #include <boost/function.hpp>
  11. #include <iostream>
  12. #include "../tutorial_common/my_plugin_api.hpp"
  13. namespace dll = boost::dll;
  14. int main(int argc, char* argv[]) {
  15. /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/
  16. boost::dll::fs::path shared_library_path(argv[1]); // argv[1] contains path to directory with our plugin library
  17. shared_library_path /= "my_plugin_aggregator";
  18. typedef boost::shared_ptr<my_plugin_api> (pluginapi_create_t)();
  19. boost::function<pluginapi_create_t> creator;
  20. creator = boost::dll::import_alias<pluginapi_create_t>( // type of imported symbol must be explicitly specified
  21. shared_library_path, // path to library
  22. "create_plugin", // symbol to import
  23. dll::load_mode::append_decorations // do append extensions and prefixes
  24. );
  25. boost::shared_ptr<my_plugin_api> plugin = creator();
  26. std::cout << "plugin->calculate(1.5, 1.5) call: " << plugin->calculate(1.5, 1.5) << std::endl;
  27. std::cout << "plugin->calculate(1.5, 1.5) second call: " << plugin->calculate(1.5, 1.5) << std::endl;
  28. std::cout << "Plugin Name: " << plugin->name() << std::endl;
  29. }
  30. //]