blob: cb4969609d8f4b12bfb6bb42c73436396702d2b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright 2019 Ramil Gauss.
// Copyright 2019 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/predef.h>
#if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
#include <boost/dll/smart_library.hpp>
#include <boost/dll/import_mangled.hpp>
#include <boost/dll/import_class.hpp>
#include <iostream>
#include <string>
#include "../example/b2_workarounds.hpp"
#include <boost/core/lightweight_test.hpp>
namespace space {
class BOOST_SYMBOL_EXPORT my_plugin {
public:
template <typename Arg>
BOOST_SYMBOL_EXPORT int Func(); // defined in cpp_test_library.cpp
};
}
int main(int argc, char** argv) {
unsigned matches_found = 0;
boost::dll::fs::path lib_path = b2_workarounds::first_lib_from_argv(argc, argv);
boost::dll::experimental::smart_library lib(lib_path);
auto storage = lib.symbol_storage().get_storage();
for (auto& s : storage) {
auto& demangled = s.demangled;
BOOST_TEST(demangled.data());
auto beginFound = demangled.find("Func<");
if (beginFound == std::string::npos)
continue;
auto endFound = demangled.find("(");
if (endFound == std::string::npos)
continue;
// Usually "Func<space::my_plugin>" on Linux, "Func<class space::my_plugin>" on Windows.
auto funcName = demangled.substr(beginFound, endFound - beginFound);
std::cout << "Function name: " << funcName.data() << std::endl;
auto typeIndexFunc = boost::dll::experimental::import_mangled<space::my_plugin, int()>(lib, funcName);
space::my_plugin cl;
BOOST_TEST_EQ(typeIndexFunc(&cl), 42);
++matches_found;
break;
}
BOOST_TEST_EQ(matches_found, 1);
return boost::report_errors();
}
#else
int main() {}
#endif
|