1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin. 2 // Copyright 2015-2019 Antony Polukhin. 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 // MinGW related workaround 9 #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION 10 11 #include <boost/dll.hpp> 12 #include <string> 13 14 #ifdef BOOST_NO_CXX11_NOEXCEPT 15 #define noexcept 16 #endif 17 18 #define API extern "C" BOOST_SYMBOL_EXPORT 19 20 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 21 //[getting_started_exports_cpp11_function 22 namespace some_namespace { 23 API int i_am_a_cpp11_function(std::string&& param) noexcept; 24 // ^-------------------- function name to use in dll::import<> 25 } 26 //] 27 #endif 28 29 30 //[getting_started_exports_cpp_variable 31 namespace your_project_namespace { 32 API std::string cpp_variable_name; 33 } 34 //] 35 36 37 38 //[getting_started_exports_alias 39 namespace some_namespace { 40 std::string i_am_function_with_ugly_name(const std::string& param) noexcept; 41 } 42 43 // When you have no control over function sources or wish to specify another name. 44 BOOST_DLL_ALIAS(some_namespace::i_am_function_with_ugly_name, pretty_name) 45 //] 46 47 //[getting_started_exports_c_function 48 API int c_func_name(int); 49 //] 50 51 //[getting_started_exports_c_variable 52 API int c_variable_name; 53 //] 54 c_func_name(int i)55int c_func_name(int i) { return ++i; } 56 int c_variable_name = 1; 57 std::string your_project_namespace::cpp_variable_name = "some value"; 58 59 namespace some_namespace { i_am_function_with_ugly_name(const std::string & param)60 std::string i_am_function_with_ugly_name(const std::string& param) noexcept { 61 return param + " Hello from lib!"; 62 } 63 64 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES i_am_a_cpp11_function(std::string && param)65 int i_am_a_cpp11_function(std::string&& param) noexcept { 66 return static_cast<int>(param.size()); 67 } 68 #endif 69 } 70 71