tutorial1.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031
  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" // contains dll_test::replace_with_full_path
  8. //[callplugcpp_tutorial1
  9. #include <boost/dll/import.hpp> // for import_alias
  10. #include <iostream>
  11. #include "../tutorial_common/my_plugin_api.hpp"
  12. namespace dll = boost::dll;
  13. int main(int argc, char* argv[]) {
  14. /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/
  15. boost::dll::fs::path lib_path(argv[1]); // argv[1] contains path to directory with our plugin library
  16. boost::shared_ptr<my_plugin_api> plugin; // variable to hold a pointer to plugin variable
  17. std::cout << "Loading the plugin" << std::endl;
  18. plugin = dll::import<my_plugin_api>( // type of imported symbol is located between `<` and `>`
  19. lib_path / "my_plugin_sum", // path to the library and library name
  20. "plugin", // name of the symbol to import
  21. dll::load_mode::append_decorations // makes `libmy_plugin_sum.so` or `my_plugin_sum.dll` from `my_plugin_sum`
  22. );
  23. std::cout << "plugin->calculate(1.5, 1.5) call: " << plugin->calculate(1.5, 1.5) << std::endl;
  24. }
  25. //]