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/03/01 14:46:45 $
12 * ------------------------------------------------------------------------*/
19 #if HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
24 #if 0 /* apparently unused */
25 ObjectFile loadLibrary(fn)
27 return dlopen(fn,RTLD_NOW | RTLD_GLOBAL);
30 void* lookupSymbol(file,symbol)
33 return dlsym(file,symbol);
37 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
41 ObjectFile instance = dlopen(dll,RTLD_NOW);
42 #elif defined RTLD_LAZY /* eg SunOS4 doesn't have RTLD_NOW */
43 ObjectFile instance = dlopen(dll,RTLD_LAZY);
44 #else /* eg FreeBSD doesn't have RTLD_LAZY */
45 ObjectFile instance = dlopen(dll,1);
47 if (NULL == instance) {
48 ERRMSG(0) "Error %s while importing DLL \"%s\"", dlerror(), dll
51 return dlsym(instance,symbol);
54 #elif HAVE_DL_H /* eg HPUX */
58 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
61 ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L);
63 if (NULL == instance) {
64 ERRMSG(0) "Error while importing DLL \"%s\"", dll
67 return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;
70 #elif HAVE_WINDOWS_H && !defined(__MSDOS__)
74 ObjectFile loadLibrary(fn)
76 return LoadLibrary(fn);
79 void* lookupSymbol(file,symbol)
82 return GetProcAddress(file,symbol);
85 const char *dlerror(void)
90 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
93 ObjectFile instance = LoadLibrary(dll);
94 if (NULL == instance) {
95 /* GetLastError allegedly provides more detail - in practice,
96 * it tells you nothing more.
98 ERRMSG(0) "Error while importing DLL \"%s\"", dll
101 return GetProcAddress(instance,symbol);
104 #else /* Dynamic loading not available */
106 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
109 #if 1 /* very little to choose between these options */
112 ERRMSG(0) "This Hugs build does not support dynamic loading\n"
117 #endif /* Dynamic loading not available */