summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/dll/example/getting_started_library.cpp
blob: 0264fd33bb85f543fff4ea4143cd3f404186f69b (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
68
69
70
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
// Copyright 2015-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)

// MinGW related workaround
#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION

#include <boost/dll.hpp>
#include <string>

#ifdef BOOST_NO_CXX11_NOEXCEPT
#define noexcept
#endif

#define API extern "C" BOOST_SYMBOL_EXPORT

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//[getting_started_exports_cpp11_function
namespace some_namespace {
    API int i_am_a_cpp11_function(std::string&& param) noexcept;
//          ^--------------------  function name to use in dll::import<>
}
//]
#endif


//[getting_started_exports_cpp_variable
namespace your_project_namespace {
    API std::string cpp_variable_name;
}
//]



//[getting_started_exports_alias
namespace some_namespace {
    std::string i_am_function_with_ugly_name(const std::string& param) noexcept;
}

// When you have no control over function sources or wish to specify another name.
BOOST_DLL_ALIAS(some_namespace::i_am_function_with_ugly_name, pretty_name)
//]

//[getting_started_exports_c_function
API int c_func_name(int);
//]

//[getting_started_exports_c_variable
API int c_variable_name;
//]

int c_func_name(int i) { return ++i; }
int c_variable_name = 1;
std::string your_project_namespace::cpp_variable_name = "some value";

namespace some_namespace {
    std::string i_am_function_with_ugly_name(const std::string& param) noexcept {
        return param + " Hello from lib!";
    }

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
    int i_am_a_cpp11_function(std::string&& param) noexcept {
        return static_cast<int>(param.size());
    }
#endif
}