]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial2/tutorial2.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015 Antony Polukhin.
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)
8 #include "../b2_workarounds.hpp"
10 //[callplugcpp_tutorial2
11 #include <boost/dll/import.hpp> // for import_alias
12 #include <boost/function.hpp>
14 #include "../tutorial_common/my_plugin_api.hpp"
16 namespace dll
= boost::dll
;
18 int main(int argc
, char* argv
[]) {
19 /*<-*/ b2_workarounds::argv_to_path_guard
guard(argc
, argv
); /*->*/
20 boost::filesystem::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
;
25 creator
= boost::dll::import_alias
<pluginapi_create_t
>( // type of imported symbol must be explicitly specified
26 shared_library_path
, // path to library
27 "create_plugin", // symbol to import
28 dll::load_mode::append_decorations
// do append extensions and prefixes
31 boost::shared_ptr
<my_plugin_api
> plugin
= creator();
32 std::cout
<< "plugin->calculate(1.5, 1.5) call: " << plugin
->calculate(1.5, 1.5) << std::endl
;
33 std::cout
<< "plugin->calculate(1.5, 1.5) second call: " << plugin
->calculate(1.5, 1.5) << std::endl
;
34 std::cout
<< "Plugin Name: " << plugin
->name() << std::endl
;