1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (C) 2021 COIN-OR Foundation
// All Rights Reserved.
// This code is published under the Eclipse Public License.
#ifndef __IPLIBRARYLOADER_HPP__
#define __IPLIBRARYLOADER_HPP__
#include "IpReferenced.hpp"
#include "IpException.hpp"
#ifdef _WIN32
# define IPOPT_SHAREDLIBEXT "dll"
#elif defined(__APPLE__)
# define IPOPT_SHAREDLIBEXT "dylib"
#else
# define IPOPT_SHAREDLIBEXT "so"
#endif
namespace Ipopt
{
/** loading of a library at runtime
*
* wrapper around dlopen()/dlsym() and variants
* @since 3.14.0
*/
class IPOPTLIB_EXPORT LibraryLoader : public ReferencedObject
{
private:
std::string libname;
void* libhandle;
/** unimplemented copy constructor */
LibraryLoader(const LibraryLoader&);
/** unimplemented assigment operator */
LibraryLoader& operator=(const LibraryLoader&);
public:
/** constructor */
LibraryLoader(
const std::string& libname_ /**< full name of library, can include path */
)
: libname(libname_),
libhandle(NULL)
{ }
/** destructor */
~LibraryLoader()
{
unloadLibrary();
}
/** tries to load library */
void loadLibrary();
/** unload library, if loaded */
void unloadLibrary();
/** tries to load symbol
*
* calls loadLibrary() if no library loaded yet
*/
void* loadSymbol(
const std::string& symbolname /**< base name of symbol */
);
};
/** a problem occurred with a a dynamically loaded library
*
* e.g., library could not be loaded or a symbol could not be found
*/
DECLARE_STD_EXCEPTION(DYNAMIC_LIBRARY_FAILURE);
} // namespace Ipopt
#endif /* __IPLIBRARYLOADER_HPP__ */