87 DynamicLib(std::shared_ptr<GLogger> logger, std::string path) : dlFileName(path), log(logger),
handle(nullptr) {
89 log->debug(
NORMAL,
"Trying %1", dlFileName);
92 if (!doesFileExists(dlFileName)) {
93 log->debug(
NORMAL,
"%1 not found...", dlFileName);
95 if (
const char* envPath = std::getenv(
"GEMC_PLUGIN_PATH")) {
96 std::istringstream ss(envPath);
98 while (std::getline(ss, dir,
':')) {
99 const std::string candidate = dir +
"/" + path;
100 if (doesFileExists(candidate)) {
101 dlFileName = candidate;
106 log->debug(
NORMAL,
"Trying %1", dlFileName);
110 if (!doesFileExists(dlFileName)) {
111 log->debug(
NORMAL,
"%1 not found...", dlFileName);
114 dlFileName = gemcRoot.string() +
"/lib/" + path;
116 log->debug(
NORMAL,
"Trying %1", dlFileName);
120 if (!doesFileExists(dlFileName)) {
121 log->debug(
NORMAL,
"%1 not found...", dlFileName);
124 dlFileName = gemcRoot.string() +
"/build/" + path;
126 log->debug(
NORMAL,
"Trying %1", dlFileName);
129 if (doesFileExists(dlFileName)) {
130 dlFileName = std::filesystem::absolute(dlFileName).string();
131 handle = load_lib(dlFileName);
133 char const*
const dlopen_error = dlerror();
136 dlFileName, dlopen_error !=
nullptr ? dlopen_error :
"unknown dlopen error");
138 else { log->info(1,
"Loaded %1", dlFileName); }
141 const char* envPath = std::getenv(
"GEMC_PLUGIN_PATH");
144 "could not find %1\n GEMC_PLUGIN_PATH = %2\n Hint: set GEMC_PLUGIN_PATH or use "
145 "-plugin_path=<dir> to the directory containing *.gplugin files.", dlFileName,
146 (envPath ? envPath :
"(not set)"));