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/06/07 17:22:31 $
12 * ------------------------------------------------------------------------*/
19 #if HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
24 ObjectFile loadLibrary(fn)
26 return dlopen(fn,RTLD_NOW | RTLD_GLOBAL);
29 void* lookupSymbol(file,symbol)
32 return dlsym(file,symbol);
35 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
39 ObjectFile instance = dlopen(dll,RTLD_NOW);
40 #elif defined RTLD_LAZY /* eg SunOS4 doesn't have RTLD_NOW */
41 ObjectFile instance = dlopen(dll,RTLD_LAZY);
42 #else /* eg FreeBSD doesn't have RTLD_LAZY */
43 ObjectFile instance = dlopen(dll,1);
45 if (NULL == instance) {
46 ERRMSG(0) "Error %s while importing DLL \"%s\"", dlerror(), dll
49 return dlsym(instance,symbol);
52 #elif HAVE_DL_H /* eg HPUX */
56 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
59 ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L);
61 if (NULL == instance) {
62 ERRMSG(0) "Error while importing DLL \"%s\"", dll
65 return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;
68 #elif HAVE_WINDOWS_H && !defined(__MSDOS__)
72 ObjectFile loadLibrary(fn)
74 return LoadLibrary(fn);
77 void* lookupSymbol(file,symbol)
80 return GetProcAddress(file,symbol);
83 const char *dlerror(void)
88 void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */
91 ObjectFile instance = LoadLibrary(dll);
92 if (NULL == instance) {
93 /* GetLastError allegedly provides more detail - in practice,
94 * it tells you nothing more.
96 ERRMSG(0) "Error while importing DLL \"%s\"", dll
99 return GetProcAddress(instance,symbol);
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 */