Loading...
Searching...
No Matches
dynamic_library.h
Go to the documentation of this file.
1#ifndef _BBM_DYNAMIC_LIBRARY_H_
2#define _BBM_DYNAMIC_LIBRARY_H_
3
4#include <string>
5
6/***********************************************************************/
7/*! \file dynamic_library.h
8 \brief load and unload a dynamic library
9************************************************************************/
10
11#ifdef __WINDOWS__
12 #include <windows.h>
13
14 namespace bbm {
15
16 using dl_handle_t = HMODULE;
17
18 inline dl_handle_t loadDynamicLibrary(const std::string& name)
19 {
20 return LoadLibraryW(name.c_str());
21 }
22
23 inline void closeDynamicLibrary(dl_handle_t handle)
24 {
25 FreeLibrary(handle);
26 }
27
28 } // end bbm namespace
29
30#else
31 #include <dlfcn.h>
32
33 namespace bbm {
34
35 using dl_handle_t = void*;
36
37 inline dl_handle_t loadDynamicLibrary(const std::string& name)
38 {
39 return dlopen(name.c_str(), RTLD_LAZY | RTLD_GLOBAL);
40 }
41
42 inline void closeDynamicLibrary(dl_handle_t handle)
43 {
44 dlclose(handle);
45 }
46
47 } // end bbm namespace
48
49#endif
50
51#endif /* _BBM_DYNAMIC_LIBRARY_H_ */
Definition: aggregatebsdf.h:29
dl_handle_t loadDynamicLibrary(const std::string &name)
Definition: dynamic_library.h:37
void * dl_handle_t
Definition: dynamic_library.h:35
void closeDynamicLibrary(dl_handle_t handle)
Definition: dynamic_library.h:42