1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief POSIX compatible loader for a shared object
7 * @file lin_shared_object_loader.h
13 #include "../../ie_api.h"
14 #include "../ie_exception.hpp"
16 namespace InferenceEngine {
20 * @brief This class provides an OS shared module abstraction
22 class SharedObjectLoader {
24 void *shared_object = nullptr;
28 * @brief Loads a library with the name specified. The library is loaded according to
29 * the POSIX rules for dlopen
30 * @param pluginName Full or relative path to the library
32 explicit SharedObjectLoader(const char* pluginName) {
33 shared_object = dlopen(pluginName, RTLD_LAZY);
35 if (shared_object == nullptr)
36 THROW_IE_EXCEPTION << "Cannot load library '" << pluginName << "': " << dlerror();
38 ~SharedObjectLoader() noexcept(false) {
39 if (0 != dlclose(shared_object)) {
40 THROW_IE_EXCEPTION << "dlclose failed: " << dlerror();
45 * @brief Searches for a function symbol in the loaded module
46 * @param symbolName Name of the function to find
47 * @return A pointer to the function if found
48 * @throws InferenceEngineException if the function is not found
50 void *get_symbol(const char* symbolName) const {
51 void * procAddr = nullptr;
53 procAddr = dlsym(shared_object, symbolName);
54 if (procAddr == nullptr)
55 THROW_IE_EXCEPTION << "dlSym cannot locate method '" << symbolName << "': " << dlerror();
60 } // namespace details
61 } // namespace InferenceEngine