2 /* --------------------------------------------------------------------------
3 * Dynamic loading (of .dll or .so files) for Hugs
5 * Copyright (c) The University of Nottingham and Yale University, 1994-1997.
6 * All rights reserved. See NOTICE for details and conditions of use etc...
7 * Hugs version 1.4, December 1997
9 * $RCSfile: dynamic.c,v $
11 * $Date: 1999/10/15 19:11:54 $
12 * ------------------------------------------------------------------------*/
19 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
23 ObjectFile loadLibrary(fn)
25 return LoadLibrary(fn);
28 void* lookupSymbol(file,symbol)
31 return GetProcAddress(file,symbol);
34 const char *dlerror(void)
39 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
42 ObjectFile instance = LoadLibrary(dll);
43 if (NULL == instance) {
44 /* GetLastError allegedly provides more detail - in practice,
45 * it tells you nothing more.
47 ERRMSG(0) "Error while importing DLL \"%s\"", dll
50 return GetProcAddress(instance,symbol);
53 #elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
58 ObjectFile loadLibrary(fn)
60 return dlopen(fn,RTLD_NOW | RTLD_GLOBAL);
63 void* lookupSymbol(file,symbol)
66 return dlsym(file,symbol);
69 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
73 ObjectFile instance = dlopen(dll,RTLD_NOW);
74 #elif defined RTLD_LAZY /* eg SunOS4 doesn't have RTLD_NOW */
75 ObjectFile instance = dlopen(dll,RTLD_LAZY);
76 #else /* eg FreeBSD doesn't have RTLD_LAZY */
77 ObjectFile instance = dlopen(dll,1);
79 if (NULL == instance) {
80 ERRMSG(0) "Error %s while importing DLL \"%s\"", dlerror(), dll
83 return dlsym(instance,symbol);
86 #elif HAVE_DL_H /* eg HPUX */
90 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
93 ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L);
95 if (NULL == instance) {
96 ERRMSG(0) "Error while importing DLL \"%s\"", dll
99 return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;
102 #else /* Dynamic loading not available */
104 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
107 #if 1 /* very little to choose between these options */
110 ERRMSG(0) "This Hugs build does not support dynamic loading\n"
115 #endif /* Dynamic loading not available */