search dependencies in the library dir

This instructs LoadLibrary to search dependent libraries in the dir
where the module resides.
This commit is contained in:
Xiaoqiang Wang
2020-01-07 16:43:11 +01:00
parent 09864f61d4
commit 043acfe894
2 changed files with 23 additions and 14 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ USR_INCLUDES_Linux=-idirafter ${EPICS_BASE}/include
USR_CFLAGS += -DT_A='"${T_A}"'
# This should really go into some global WIN32 config file
USR_CFLAGS_WIN32 += /D_WIN32_WINNT=0x501
USR_CFLAGS_WIN32 += /D_WIN32_WINNT=0x502
dbLoadTemplate.c: dbLoadTemplate_lex.c ../dbLoadTemplate.h
+22 -13
View File
@@ -300,21 +300,30 @@ static HMODULE loadlib(const char* libname)
libname, dlerror());
}
#elif defined (_WIN32)
if ((libhandle = LoadLibrary(libname)) == NULL)
{
LPVOID lpMsgBuf;
char *p;
char *libpath = strdup(libname);
if ((p = strrchr(libpath, '/')) != NULL)
*p = '\0';
SetDllDirectory(libpath);
if ((libhandle = LoadLibrary(libname)) == NULL)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
fprintf (stderr, "Loading %s library failed: %s\n",
libname, lpMsgBuf);
LocalFree(lpMsgBuf);
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
fprintf (stderr, "Loading %s library failed: %s\n",
libname, lpMsgBuf);
LocalFree(lpMsgBuf);
}
free(libpath);
SetDllDirectory(NULL);
}
#elif defined (vxWorks)
{