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