85 DynamicLib(std::shared_ptr<GLogger> logger, std::string path) : dlFileName(path), log(logger),
handle(nullptr) {
87 log->debug(
NORMAL,
"Trying ", dlFileName);
90 if (!doesFileExists(dlFileName)) {
91 log->debug(
NORMAL, dlFileName,
" not found...");
93 if (
const char* envPath = std::getenv(
"GEMC_PLUGIN_PATH")) {
94 std::istringstream ss(envPath);
96 while (std::getline(ss, dir,
':')) {
97 const std::string candidate = dir +
"/" + path;
98 if (doesFileExists(candidate)) {
99 dlFileName = candidate;
104 log->debug(
NORMAL,
"Trying ", dlFileName);
108 if (!doesFileExists(dlFileName)) {
109 log->debug(
NORMAL, dlFileName,
" not found...");
112 dlFileName = gemcRoot.string() +
"/lib/" + path;
114 log->debug(
NORMAL,
"Trying ", dlFileName);
118 if (!doesFileExists(dlFileName)) {
119 log->debug(
NORMAL, dlFileName,
" not found...");
122 dlFileName = gemcRoot.string() +
"/build/" + path;
124 log->debug(
NORMAL,
"Trying ", dlFileName);
127 if (doesFileExists(dlFileName)) {
128 dlFileName = std::filesystem::absolute(dlFileName).string();
129 handle = load_lib(dlFileName);
131 char const*
const dlopen_error = dlerror();
132 log->error(
ERR_DLHANDLENOTFOUND,
"File ", dlFileName,
" found, but handle is null. dlopen_error >> ",
133 dlopen_error !=
nullptr ? dlopen_error :
"unknown dlopen error");
135 else { log->info(1,
"Loaded ", dlFileName); }
138 const char* envPath = std::getenv(
"GEMC_PLUGIN_PATH");
140 "could not find ", dlFileName,
"\n",
141 " GEMC_PLUGIN_PATH = ", (envPath ? envPath :
"(not set)"),
"\n",
142 " Hint: set GEMC_PLUGIN_PATH or use -plugin_path=<dir> to the directory ",
143 "containing *.gplugin files.");