]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial7/tutorial7.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)
9 #include "../b2_workarounds.hpp"
11 //[callplugcpp_tutorial7
12 #include <boost/dll/shared_library.hpp>
13 #include <boost/dll/library_info.hpp>
16 void load_and_execute(const boost::dll::fs::path libraries
[], std::size_t libs_count
) {
17 const std::string username
= "User";
19 for (std::size_t i
= 0; i
< libs_count
; ++i
) {
20 // Class `library_info` can extract information from a library
21 boost::dll::library_info
inf(libraries
[i
]);
23 // Getting symbols exported from 'Anna' section
24 std::vector
<std::string
> exports
= inf
.symbols("Anna");
26 // Loading library and importing symbols from it
27 boost::dll::shared_library
lib(libraries
[i
]);
28 for (std::size_t j
= 0; j
< exports
.size(); ++j
) {
29 std::cout
<< "\nFunction '" << exports
[j
] << "' prints:\n\t";
30 lib
.get_alias
<void(const std::string
&)>(exports
[j
]) // importing function
31 (username
); // calling function
37 int main(int argc
, char* argv
[]) {
38 /*<-*/ BOOST_ASSERT(argc
>= 3); /*->*/
39 std::vector
<boost::dll::fs::path
> libraries
;
40 libraries
.reserve(argc
- 1);
41 for (int i
= 1; i
< argc
; ++i
) {
42 if (b2_workarounds::is_shared_library(argv
[i
])) {
43 libraries
.push_back(argv
[i
]);
47 load_and_execute(&libraries
[0], libraries
.size());