14#include "arccore/base/String.h"
15#include "arccore/base/PlatformUtils.h"
17#include "arccore/base/internal/IDynamicLibraryLoader.h"
36class GlibDynamicLibrary
48 void close()
override;
54 GModule* m_gmodule =
nullptr;
63class GlibDynamicLibraryLoader
68 GlibDynamicLibraryLoader()
71 if (s ==
"1" || s ==
"true")
75 void build()
override {}
84#ifdef ARCCORE_OS_WIN32
85 dl = _tryOpen(directory, name +
".dll");
87#ifdef ARCCORE_OS_MACOS
88 dl = _tryOpen(directory,
"lib" + name +
".dylib");
93 dl = _tryOpen(
".", name);
98#ifdef ARCCORE_OS_WIN32
99 dl = _tryOpen(
".", name +
".dll");
101#ifdef ARCCORE_OS_MACOS
102 dl = _tryOpen(
".",
"lib" + name +
".dylib");
110 const gchar* gdirectory =
reinterpret_cast<const gchar*
>(directory.
utf8().data());
111 const gchar* gname =
reinterpret_cast<const gchar*
>(name.
utf8().data());
112 gchar* full_path = g_module_build_path(gdirectory, gname);
114 std::cout <<
"** Load Dynamic Library '" << full_path <<
"'...";
116 GModule* gmodule = g_module_open(full_path, GModuleFlags());
120 std::cout <<
" NOT FOUND\n";
123 std::cout <<
" OK\n";
128 auto lib =
new GlibDynamicLibrary(
this, gmodule);
129 m_opened_libraries.insert(lib);
136 std::vector<GlibDynamicLibrary*> libs(m_opened_libraries.begin(), m_opened_libraries.end());
137 for (
auto lib : libs) {
145 auto iter = m_opened_libraries.find(lib);
146 if (iter != m_opened_libraries.end())
147 m_opened_libraries.erase(iter);
152 bool m_is_verbose =
false;
153 std::set<GlibDynamicLibrary*> m_opened_libraries;
164 bool is_ok = g_module_close(m_gmodule);
167 std::cerr <<
"WARNING: can not unload module\n";
168 m_manager->removeInstance(
this);
181 const gchar* gname =
reinterpret_cast<const gchar*
>(symbol_name.
utf8().data());
182 void* symbol_addr =
nullptr;
183 bool r = ::g_module_symbol(m_gmodule, gname, &symbol_addr);
193createGlibDynamicLibraryLoader()
204 GlibDynamicLibraryLoader glib_dynamic_loader;
205 IDynamicLibraryLoader* global_default_loader = &glib_dynamic_loader;
210 return global_default_loader;
Types and functions associated with the classes ArrayView and ConstArrayView.
Interface for a dynamic library loader.
IDynamicLibrary * open(const String &directory, const String &name) override
Loads a dynamic library.
void closeLibraries() override
Closes all libraries opened via open().
void close() override
Closes the dynamic library.
void * getSymbolAddress(const String &symbol_name, bool *is_found) override
Returns the address of the symbol named symbol_name.
Interface of a dynamic library loader.
static IDynamicLibraryLoader * getDefault()
Service used for dynamically loading libraries.
Interface of a dynamic library.
Unicode character string.
ByteConstArrayView utf8() const
Returns the conversion of the instance into UTF-8 encoding.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --