| 1 | // Copyright 2014 Renato Tegon Forti, Antony Polukhin. |
| 2 | // Copyright Antony Polukhin, 2015-2024. |
| 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 | |
| 8 | #include "../b2_workarounds.hpp" |
| 9 | |
| 10 | //[callplugcpp_tutorial2 |
| 11 | #include <boost/dll/import.hpp> // for import_alias |
| 12 | #include <boost/function.hpp> |
| 13 | #include <iostream> |
| 14 | #include "../tutorial_common/my_plugin_api.hpp" |
| 15 | |
| 16 | namespace dll = boost::dll; |
| 17 | |
| 18 | int main(int argc, char* argv[]) { |
| 19 | /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/ |
| 20 | boost::dll::fs::path shared_library_path(argv[1]); // argv[1] contains path to directory with our plugin library |
| 21 | shared_library_path /= "my_plugin_aggregator" ; |
| 22 | typedef boost::shared_ptr<my_plugin_api> (pluginapi_create_t)(); |
| 23 | boost::function<pluginapi_create_t> creator; |
| 24 | |
| 25 | creator = boost::dll::import_alias<pluginapi_create_t>( // type of imported symbol must be explicitly specified |
| 26 | lib: shared_library_path, // path to library |
| 27 | name: "create_plugin" , // symbol to import |
| 28 | mode: dll::load_mode::append_decorations // do append extensions and prefixes |
| 29 | ); |
| 30 | |
| 31 | boost::shared_ptr<my_plugin_api> plugin = creator(); |
| 32 | std::cout << "plugin->calculate(1.5, 1.5) call: " << plugin->calculate(x: 1.5, y: 1.5) << std::endl; |
| 33 | std::cout << "plugin->calculate(1.5, 1.5) second call: " << plugin->calculate(x: 1.5, y: 1.5) << std::endl; |
| 34 | std::cout << "Plugin Name: " << plugin->name() << std::endl; |
| 35 | } |
| 36 | //] |
| 37 | |