1// Copyright 2011-2012 Renato Tegon Forti
2// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
3// Copyright Antony Polukhin, 2015-2024.
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt
7// or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9// For more information, see http://www.boost.org
10
11// MinGW related workaround
12#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
13
14#include <boost/dll/config.hpp>
15#include <boost/dll/alias.hpp>
16#include <iostream>
17#include <vector>
18
19#include <boost/shared_ptr.hpp>
20#include <boost/make_shared.hpp>
21#include <boost/fusion/container.hpp>
22
23#define LIBRARY_API BOOST_SYMBOL_EXPORT
24
25extern "C" void LIBRARY_API say_hello(void);
26extern "C" float LIBRARY_API lib_version(void);
27extern "C" int LIBRARY_API increment(int);
28
29#if defined(__GNUC__) && __GNUC__ >= 4 && defined(__ELF__)
30extern "C" int __attribute__((visibility ("protected"))) protected_function(int);
31#endif
32
33extern "C" int LIBRARY_API integer_g;
34extern "C" const int LIBRARY_API const_integer_g = 777;
35
36namespace foo {
37 std::size_t bar(const std::vector<int>& v) {
38 return v.size();
39 }
40
41 std::size_t variable = 42;
42}
43
44
45
46// Make sure that aliases have no problems with memory allocations and different types of input parameters
47namespace namespace1 { namespace namespace2 { namespace namespace3 {
48 typedef
49 boost::fusion::vector<std::vector<int>, std::vector<int>, std::vector<int>, const std::vector<int>*, std::vector<int>* >
50 do_share_res_t;
51
52 boost::shared_ptr<do_share_res_t> do_share(
53 std::vector<int> v1,
54 std::vector<int>& v2,
55 const std::vector<int>& v3,
56 const std::vector<int>* v4,
57 std::vector<int>* v5
58 )
59 {
60 v2.back() = 777;
61 v5->back() = 9990;
62 return boost::make_shared<do_share_res_t>(args&: v1, args&: v2, args: v3, args&: v4, args&: v5);
63 }
64
65 std::string info("I am a std::string from the test_library (Think of me as of 'Hello world'. Long 'Hello world').");
66
67 int& ref_returning_function() {
68 static int i = 0;
69 return i;
70 }
71}}}
72
73
74
75BOOST_DLL_ALIAS(foo::bar, foo_bar)
76BOOST_DLL_ALIAS(foo::variable, foo_variable)
77BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::do_share, do_share)
78BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::info, info)
79BOOST_DLL_ALIAS(const_integer_g, const_integer_g_alias)
80BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::ref_returning_function, ref_returning_function)
81
82
83
84int integer_g = 100;
85
86void say_hello(void)
87{
88 std::cout << "Hello, Boost.Application!" << std::endl;
89}
90
91float lib_version(void)
92{
93 return 1.0;
94}
95
96int increment(int n)
97{
98 return ++n;
99}
100
101#if defined(__GNUC__) && __GNUC__ >= 4 && defined(__ELF__)
102int protected_function(int) {
103 return 42;
104}
105#endif
106
107
108#include <boost/dll/runtime_symbol_info.hpp>
109
110boost::dll::fs::path this_module_location_from_itself() {
111 return boost::dll::this_line_location();
112}
113
114BOOST_DLL_ALIAS(this_module_location_from_itself, module_location_from_itself)
115
116
117
118int internal_integer_i = 0xFF0000;
119extern "C" LIBRARY_API int& reference_to_internal_integer;
120int& reference_to_internal_integer = internal_integer_i;
121
122#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
123extern "C" LIBRARY_API int&& rvalue_reference_to_internal_integer;
124int&& rvalue_reference_to_internal_integer = static_cast<int&&>(internal_integer_i);
125#endif
126
127

source code of boost/libs/dll/test/test_library.cpp