]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial6/tutorial6.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_tutorial6
11 #include <boost/dll/import.hpp>
12 #include <boost/function.hpp>
15 typedef boost::function
<void()> callback_t
;
17 void print_unloaded() {
18 std::cout
<< "unloaded" << std::endl
;
21 int main(int argc
, char* argv
[]) {
22 // argv[1] contains full path to our plugin library
23 boost::filesystem::path shared_library_path
= /*<-*/ b2_workarounds::first_lib_from_argv(argc
, argv
); /*->*/ //=argv[1];
25 // loading library and getting a function from it
26 boost::function
<void(const callback_t
&)> on_unload
27 = boost::dll::import_alias
<void(const callback_t
&)>(
28 shared_library_path
, "on_unload"
31 on_unload(&print_unloaded
); // adding a callback
32 std::cout
<< "Before library unload." << std::endl
;
34 // Releasing last reference to the library, so that it gets unloaded
36 std::cout
<< "After library unload." << std::endl
;