diff --git a/src/native/common/devil/extil.c b/src/native/common/devil/extil.c index 411db90f..fb196c36 100644 --- a/src/native/common/devil/extil.c +++ b/src/native/common/devil/extil.c @@ -5,6 +5,7 @@ #else #include #include "extil.h" + #include static void* devILhandle; #endif @@ -69,10 +70,18 @@ bool extil_Open(JNIEnv *env, jobjectArray ilPaths) { #ifdef _WIN32 devILhandle = LoadLibrary(path_str); #else - devILhandle = dlopen(path_str, RTLD_LAZY); + char* directoryName = dirname(path_str); + char* fileName = basename(path_str); + char* currentDirectory = getwd(NULL); + if(directoryName != NULL) { + chdir(directoryName); + } + devILhandle = dlopen(fileName, RTLD_LAZY); if(devILhandle == NULL) { - printfDebug("dlopen failure: %s", dlerror()); + printfDebug("dlopen failure: %s\n\n\n", dlerror()); } + chdir(currentDirectory); + free(currentDirectory); #endif if (devILhandle != NULL) { printfDebug("Found devil at '%s'\n", path_str); diff --git a/src/native/common/devil/extilu.c b/src/native/common/devil/extilu.c index bba59c72..e57913f9 100644 --- a/src/native/common/devil/extilu.c +++ b/src/native/common/devil/extilu.c @@ -5,6 +5,7 @@ #else #include #include "extilu.h" + #include static void* devILUhandle; #endif @@ -58,10 +59,18 @@ bool extilu_Open(JNIEnv *env, jobjectArray ilPaths) { #ifdef _WIN32 devILUhandle = LoadLibrary(path_str); #else - devILUhandle = dlopen(path_str, RTLD_LAZY); + char* directoryName = dirname(path_str); + char* fileName = basename(path_str); + char* currentDirectory = getwd(NULL); + if(directoryName != NULL) { + chdir(directoryName); + } + devILUhandle = dlopen(fileName, RTLD_LAZY); if(devILUhandle == NULL) { - printfDebug("dlopen failure: %s", dlerror()); + printfDebug("dlopen failure: %s\n\n\n", dlerror()); } + chdir(currentDirectory); + free(currentDirectory); #endif if (devILUhandle != NULL) { printfDebug("Found ilu at '%s'\n", path_str); diff --git a/src/native/common/devil/extilut.c b/src/native/common/devil/extilut.c index b90ee43c..c2d604b7 100644 --- a/src/native/common/devil/extilut.c +++ b/src/native/common/devil/extilut.c @@ -5,6 +5,7 @@ #else #include #include "extilut.h" + #include static void* devILUThandle; #endif @@ -58,10 +59,18 @@ bool extilut_Open(JNIEnv *env, jobjectArray ilPaths) { #ifdef _WIN32 devILUThandle = LoadLibrary(path_str); #else - devILUThandle = dlopen(path_str, RTLD_LAZY); + char* directoryName = dirname(path_str); + char* fileName = basename(path_str); + char* currentDirectory = getwd(NULL); + if(directoryName != NULL) { + chdir(directoryName); + } + devILUThandle = dlopen(fileName, RTLD_LAZY); if(devILUThandle == NULL) { - printfDebug("dlopen failure: %s", dlerror()); + printfDebug("dlopen failure: %s\n\n\n", dlerror()); } + chdir(currentDirectory); + free(currentDirectory); #endif if (devILUThandle != NULL) { printfDebug("Found ilut at '%s'\n", path_str);