Skip to content

Commit

Permalink
Fixed directory finding mechanism for the to be loaded dynamic shared…
Browse files Browse the repository at this point in the history
… library.
  • Loading branch information
nthnn committed Nov 25, 2024
1 parent 403adf0 commit 048394f
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/n8/ast/expression/VariableDeclarationExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <n8/ast/expression/VariableDeclarationExpression.hpp>
#include <n8/core/Runtime.hpp>
#include <n8/core/SymbolTable.hpp>
#include <n8/util/PathHelper.hpp>

#if defined(__unix__) || defined(__linux__) || defined(__APPLE__)
# include <dlfcn.h>
Expand Down Expand Up @@ -64,37 +65,30 @@ NativeFunction VariableDeclarationExpression::loadNativeFunction(
void* handle;
std::string library = std::string(libName.c_str());

if(Runtime::hasLoadedLibrary(libName)) {
#if defined(__unix__) || defined(__linux__) || defined(__APPLE__)
#if defined(__APPLE__)
library += ".dylib";
#elif defined(__unix__) || defined(__linux__) || defined(__APPLE__)
library += ".so";
#elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
library += ".dll";
#endif

library += ".so";
library = N8Util::PathHelper::findSharedLibrary(library);
if(Runtime::hasLoadedLibrary(libName))
#if defined(__unix__) || defined(__linux__) || defined(__APPLE__)
handle = Runtime::getLoadedLibrary(libName);

#elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)

library += ".dll";
handle = static_cast<HMODULE>(
Runtime::getLoadedLibrary(libName)
);

#endif
}
else {
#if defined(__APPLE__)

library += ".dylib";
handle = dlopen(library.c_str(), RTLD_LAZY);

#elif defined(__unix__) || defined(__linux__)

library += ".so";
handle = dlopen(library.c_str(), RTLD_LAZY);

#elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)

library += ".dll";
handle = LoadLibraryA(library.c_str());

#endif

Runtime::addLoadedLibrary(library, handle);
Expand Down

0 comments on commit 048394f

Please sign in to comment.