]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial3/tutorial3.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright Antony Polukhin, 2015-2022.
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"
9 //[callplugcpp_tutorial3
10 #include <boost/dll/import.hpp> // for import_alias
11 #include <boost/make_shared.hpp>
12 #include <boost/function.hpp>
14 #include "../tutorial_common/my_plugin_api.hpp"
16 namespace dll
= boost::dll
;
18 std::size_t search_for_symbols(const std::vector
<boost::dll::fs::path
>& plugins
) {
19 std::size_t plugins_found
= 0;
21 for (std::size_t i
= 0; i
< plugins
.size(); ++i
) {
22 std::cout
<< "Loading plugin: " << plugins
[i
] << '\n';
23 dll::shared_library
lib(plugins
[i
], dll::load_mode::append_decorations
);
24 if (!lib
.has("create_plugin")) {
29 // library has symbol, importing...
30 typedef boost::shared_ptr
<my_plugin_api
> (pluginapi_create_t
)();
31 boost::function
<pluginapi_create_t
> creator
32 = dll::import_alias
<pluginapi_create_t
>(boost::move(lib
), "create_plugin");
34 std::cout
<< "Matching plugin name: " << creator()->name() << std::endl
;
43 int main(int argc
, char* argv
[]) {
44 BOOST_ASSERT(argc
>= 3);
45 std::vector
<boost::dll::fs::path
> plugins
;
46 plugins
.reserve(argc
- 1);
47 for (int i
= 1; i
< argc
; ++i
) {
48 if (b2_workarounds::is_shared_library(argv
[i
])) {
49 plugins
.push_back(argv
[i
]);
53 const std::size_t res
= search_for_symbols(plugins
);
54 BOOST_ASSERT(res
== 1);