]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial7/tutorial7.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / dll / example / tutorial7 / tutorial7.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright Antony Polukhin, 2015-2022.
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 <vector>
9 #include "../b2_workarounds.hpp"
10
11 //[callplugcpp_tutorial7
12 #include <boost/dll/shared_library.hpp>
13 #include <boost/dll/library_info.hpp>
14 #include <iostream>
15
16 void load_and_execute(const boost::dll::fs::path libraries[], std::size_t libs_count) {
17 const std::string username = "User";
18
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]);
22
23 // Getting symbols exported from 'Anna' section
24 std::vector<std::string> exports = inf.symbols("Anna");
25
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
32 }
33 }
34 }
35 //]
36
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]);
44 }
45 }
46
47 load_and_execute(&libraries[0], libraries.size());
48 }