Boost
C++ Libraries
...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
This is an older version of Boost and was released in 2016. The current version is 1.89.0.
dlopen like
functions. For those platforms Boost.DLL is safe in the manner as
all the C++ Standard Library containers are: it is safe to use different
instances of shared_library from different threads even if all the
instances loaded the same library. On other platforms it is not safe
to concurrently call any of the functions from Boost.DLL (even a
shared_library::location()
call triggers a race condition). See Limitations,
Thread safe library loading.
BOOST_SYMBOL_EXPORT
or BOOST_DLL_ALIAS.
You can call shared_library(program_location()) to load yourself. Refer to the
Tutorial section for more info. You can also query executables, just
provide a path to the executable to library_info
class.
shared_library::get<T>
or import<T>?
Segmentation Fault.
However it is safe to make types more strict, for example making
const int
from an int will not
harm.
BOOST_DLL_ALIAS
macros will not change with the change of compiler or platform. You
must take care of functions ABI and API stability by your own.
libsome_library
shared library. How to achieve that?
load_mode::rtld_deepbind.
Workaround would be to write plugin into a temporary file in RAM and load plugin from it:
#include <boost/filesystem.hpp> #include <boost/dll.hpp> using namespace boost; dll:shared_library load_from_memory(unsigned char* data, std::size_t size, const filesystem::path& tmp_plugin_path = filesystem::unique_path() / "libplugin.so") { const filesystem::path plugin_location = filesystem::temp_directory_path() / tmp_plugin_path; filesystem::create_directories(plugin_location.parent_path()); filesystem::ofstream ofs(plugin_location, std::ios::out|std::ios::bin|std::ios::trunc); ofs.write(data, size); return dll::shared_library(plugin_location); }
But there's no guarantee that filesystem::temp_directory_path() will actually write to RAM, that's very platform
dependent.