lkml.org 
[lkml]   [1998]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: DLLs [OFFTOPIC]
Date
> 
> I think the question was more directed towards the late binding
> aspects of DLLs. Shared ELF libraried are bound to an executable
> at link time. DLLs can be bound at link time (similar to the shared
> library) or they can be loaded (under Windows anyway) with calls to:
>
> CoLoadLibrary(char * lpszLibName, unsigned long bAutoFree);
> CoFreeLibrary(long hInst);
> CoFreeUnusedLibraries(void);
>
> This facilitates certain types of programming. The question then
> was probably, what Linux APIs can be used for late binding of a
> library (comparable to the above mentioned windows APIs).
>
> I don't know the answer, and this is off topic, but I would be
> interested in knowing the answer as well.

The traditional interface for runtime loading libraries, that are not
linked by the linker, is based on the Solaris interface.

The functions involved are:

void *dlopen (const char *filename, int flag);
const char *dlerror(void);
void *dlsym(void *handle, char *symbol);
int dlclose (void *handle);

Special symbols: _init, _fini.

flag is a flag which tells the RTLL to resolve symbols now RTLD_NOW or resolve
them as needed RTLD_LAZY. This doesn't resolve references INTO the lib, but
rather references WITHIN the lib.

Solaris documents that _init is called when the lib is loaded, and _fini
is called when it's unloaded.

The typical use is to load the lib, then use dlsym to fetch items from the
lib's symbol table.

Just a note, the easiest way to do dynamic function resolution (which Netscape
totally missed when writing the NSAPI spec, is to create a null terminated array
of function structs:

struct func {

char *name;
void *(function)(arg list);

} func_array[] {
{"function1",function1},
{"function2",function2}};


In your code which loads the library:

struct func_array **functions;

functions=dlsym(handle,"func_array");


Yes, dlsym works to get pointers to global data declarations within shared objects.

See: dlopen(3) {Solaris}

Linux does not come with the appropriate dlfcn.h therefore snarf down some stuff I
put up a LONG time ago at:

ftp.apsoft.com:/pub/Linux/module.tgz

Although the code within bears a different stipulation, I'm placing it under GPL, I'm
too lazy to unpack it and edit the files.

>
> -Erik
>

--Perry

--
Perry Harrington Linux rules all OSes. APSoft ()
email: perry@apsoft.com Think Blue. /\

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html

\
 
 \ /
  Last update: 2005-03-22 13:43    [W:0.385 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site