Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions core/nativeaot/NativeLibrary/LoadLibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

//Set this value accordingly to your workspace settings
#if defined(_WIN32)
#define PathToLibrary "bin\\Debug\\net6.0\\win-x64\\native\\NativeLibrary.dll"
#define PathToLibrary "bin\\Debug\\net7.0\\win-x64\\native\\NativeLibrary.dll"
#elif defined(__APPLE__)
#define PathToLibrary "./bin/Debug/net6.0/osx-x64/native/NativeLibrary.dylib"
#define PathToLibrary "./bin/Debug/net7.0/osx-x64/native/NativeLibrary.dylib"
#else
#define PathToLibrary "./bin/Debug/net6.0/linux-x64/native/NativeLibrary.so"
#define PathToLibrary "./bin/Debug/net7.0/linux-x64/native/NativeLibrary.so"
#endif

#ifdef _WIN32
Expand Down Expand Up @@ -60,6 +60,16 @@ int callSumFunc(char *path, char *funcName, int firstInt, int secondInt)
#else
void *handle = dlopen(path, RTLD_LAZY);
#endif
if (!handle)
{
#ifdef _WIN32
int errorCode = GetLastError();
printf("Failed to load library at specified path. Error code: %d\n", errorCode);
#else
puts("Failed to load library at specified path");
#endif
return -1;
}

typedef int(*myFunc)(int,int);
myFunc MyImport = (myFunc)symLoad(handle, funcName);
Expand All @@ -79,6 +89,16 @@ char *callSumStringFunc(char *path, char *funcName, char *firstString, char *sec
#else
void *handle = dlopen(path, RTLD_LAZY);
#endif
if (!handle)
{
#ifdef _WIN32
int errorCode = GetLastError();
printf("Failed to load library at specified path. Error code: %d\n", errorCode);
#else
puts("Failed to load library at specified path");
#endif
return nullptr;
}

// Declare a typedef
typedef char *(*myFunc)(char*,char*);
Expand Down