1 // Copyright 2019 Ramil Gauss.
2 // Copyright 2019 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 <boost/predef.h>
9 #if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
11 #include <boost/dll/smart_library.hpp>
12 #include <boost/dll/import_mangled.hpp>
13 #include <boost/dll/import_class.hpp>
18 #include "../example/b2_workarounds.hpp"
19 #include <boost/core/lightweight_test.hpp>
23 class BOOST_SYMBOL_EXPORT my_plugin
{
25 template <typename Arg
>
26 BOOST_SYMBOL_EXPORT
int Func(); // defined in cpp_test_library.cpp
30 int main(int argc
, char** argv
) {
31 unsigned matches_found
= 0;
32 boost::dll::fs::path lib_path
= b2_workarounds::first_lib_from_argv(argc
, argv
);
33 boost::dll::experimental::smart_library
lib(lib_path
);
35 auto storage
= lib
.symbol_storage().get_storage();
36 for (auto& s
: storage
) {
37 auto& demangled
= s
.demangled
;
38 BOOST_TEST(demangled
.data());
40 auto beginFound
= demangled
.find("Func<");
41 if (beginFound
== std::string::npos
)
44 auto endFound
= demangled
.find("(");
45 if (endFound
== std::string::npos
)
48 // Usually "Func<space::my_plugin>" on Linux, "Func<class space::my_plugin>" on Windows.
49 auto funcName
= demangled
.substr(beginFound
, endFound
- beginFound
);
50 std::cout
<< "Function name: " << funcName
.data() << std::endl
;
51 auto typeIndexFunc
= boost::dll::experimental::import_mangled
<space::my_plugin
, int()>(lib
, funcName
);
54 BOOST_TEST_EQ(typeIndexFunc(&cl
), 42);
59 BOOST_TEST_EQ(matches_found
, 1);
61 return boost::report_errors();