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

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

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

Post 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?
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

didn't even know Dex4U could do that...
niteice
Member
Member
Posts: 59
Joined: Tue Oct 03, 2006 3:49 pm

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

Post 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
Post Reply