test_library.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright 2011-2012 Renato Tegon Forti
  2. // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
  3. // Copyright 2015-2019 Antony Polukhin.
  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. // For more information, see http://www.boost.org
  9. // MinGW related workaround
  10. #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
  11. #include <boost/dll/config.hpp>
  12. #include <boost/dll/alias.hpp>
  13. #include <iostream>
  14. #include <vector>
  15. #include <boost/shared_ptr.hpp>
  16. #include <boost/make_shared.hpp>
  17. #include <boost/fusion/container.hpp>
  18. #define LIBRARY_API BOOST_SYMBOL_EXPORT
  19. extern "C" void LIBRARY_API say_hello(void);
  20. extern "C" float LIBRARY_API lib_version(void);
  21. extern "C" int LIBRARY_API increment(int);
  22. extern "C" int LIBRARY_API integer_g;
  23. extern "C" const int LIBRARY_API const_integer_g = 777;
  24. namespace foo {
  25. std::size_t bar(const std::vector<int>& v) {
  26. return v.size();
  27. }
  28. std::size_t variable = 42;
  29. }
  30. // Make sure that aliases have no problems with memory allocations and different types of input parameters
  31. namespace namespace1 { namespace namespace2 { namespace namespace3 {
  32. typedef
  33. boost::fusion::vector<std::vector<int>, std::vector<int>, std::vector<int>, const std::vector<int>*, std::vector<int>* >
  34. do_share_res_t;
  35. boost::shared_ptr<do_share_res_t> do_share(
  36. std::vector<int> v1,
  37. std::vector<int>& v2,
  38. const std::vector<int>& v3,
  39. const std::vector<int>* v4,
  40. std::vector<int>* v5
  41. )
  42. {
  43. v2.back() = 777;
  44. v5->back() = 9990;
  45. return boost::make_shared<do_share_res_t>(v1, v2, v3, v4, v5);
  46. }
  47. std::string info("I am a std::string from the test_library (Think of me as of 'Hello world'. Long 'Hello world').");
  48. int& ref_returning_function() {
  49. static int i = 0;
  50. return i;
  51. }
  52. }}}
  53. BOOST_DLL_ALIAS(foo::bar, foo_bar)
  54. BOOST_DLL_ALIAS(foo::variable, foo_variable)
  55. BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::do_share, do_share)
  56. BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::info, info)
  57. BOOST_DLL_ALIAS(const_integer_g, const_integer_g_alias)
  58. BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::ref_returning_function, ref_returning_function)
  59. int integer_g = 100;
  60. void say_hello(void)
  61. {
  62. std::cout << "Hello, Boost.Application!" << std::endl;
  63. }
  64. float lib_version(void)
  65. {
  66. return 1.0;
  67. }
  68. int increment(int n)
  69. {
  70. return ++n;
  71. }
  72. #include <boost/dll/runtime_symbol_info.hpp>
  73. boost::dll::fs::path this_module_location_from_itself() {
  74. return boost::dll::this_line_location();
  75. }
  76. BOOST_DLL_ALIAS(this_module_location_from_itself, module_location_from_itself)
  77. int internal_integer_i = 0xFF0000;
  78. extern "C" LIBRARY_API int& reference_to_internal_integer;
  79. int& reference_to_internal_integer = internal_integer_i;
  80. #ifndef BOOST_NO_RVALUE_REFERENCES
  81. extern "C" LIBRARY_API int&& rvalue_reference_to_internal_integer;
  82. int&& rvalue_reference_to_internal_integer = static_cast<int&&>(internal_integer_i);
  83. #endif