Page 1 of 1

list how to do runtime linking here for different OS's

Posted: Sat Dec 09, 2006 4:18 pm
by earlz
could people please list how to load an external library and use it for different OS's
by runtime linking I mean like loading a DLL(win32) or shared objects(unix)

this is my small little example type thing:

Code: Select all

#ifdef WIN32 //this is the win32 version
#define GOOD_OS
#include <windows.h>

void *LoadExLibrary(char *name){
    void *handle;
    handle=LoadLibrary(name);
    if(handle==NULL){
        panic("Error during LoadLibrary\n");
    }
    return handle;
}
void *GetExSymbol(char *name,void *ExLibrary){
    void *address;
    address=GetProcAddress(ExLibrary,name);
    return address;
}
int UnloadExLibrary(void *handle){
    int error;
    error=FreeLibrary(handle);
    return error;
}

#endif

#ifdef UNIX //For UNIX
#define GOOD_OS
#include <dlfcn.h>

void *LoadExLibrary(char *name){
    void *handle;
    handle = dlopen(name, RTLD_LAZY);
    if(!handle)
    {
       panic("Error during dlopen()\n");
       return 0;
    }
    return handle;
}
void *GetExSymbol(char *name,void *ExLibrary){
    void *address;
    address = dlsym(ExLibrary, name);
    return address;
}
int UnloadExLibrary(void *handle){
    int error;
    error = dlclose(handle);
    return error;
}
#endif

and that's all I have just win32 and a generic unix way
so please post how to do this on other OS's such as Mac, linux(heard their was a different way to do it on linux), ect..
list minority or major OS's..I just want as many as I can get

also could you please tell how to build a dynamically linkable file using gcc?

Posted: Sun Dec 10, 2006 5:18 pm
by Dex

Posted: Sun Dec 10, 2006 5:41 pm
by earlz
didn't even know Dex4U could do that...

Re: list how to do runtime linking here for different OS's

Posted: Mon Dec 11, 2006 4:04 pm
by niteice
hckr83 wrote:so please post how to do this on other OS's such as Mac, linux(heard their was a different way to do it on linux), ect..
list minority or major OS's..I just want as many as I can get
OS X uses dlopen as well.
also could you please tell how to build a dynamically linkable file using gcc?
gcc - shared