getting_started_library.cpp 1.7 KB

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