Jump to content


Linux Shared Objects


4 replies to this topic

#1 sybesis

    New Member

  • Members
  • Pip
  • 2 posts

Posted 08 January 2007 - 07:29 AM

Hi there everyone, I'm new here but well i've been reading a lot of articles.
I'm starting to develop things unix based os but i have difficulties to find some informations on shared objects. This is like dlls of windows.

I found a website but windows frozed so i lost it. I didn't had time to save the page and i can't find it anymore.

all i know is that there may be something like loadlibrary. As i can say, it looks like a shared object in linux is programmed like normal apps but there are functions that are exported.

I didn't find any other information on how to load at runtime these functions. So i could just create function pointers that will redirect on the functions of the shared object. But i can't find any linux code using getprocadress like in windows.

If someone have any information i would just be really happy. By the way, shared objects seems to be really slow compared to static linked object.

Cya

ps: devmaster is really cool :worthy:

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 January 2007 - 07:38 AM

Applications in Linux use a library called "libdl" (dl for dynamic linking) to load and link with the shared libraries. I'm sure there are functions like the Windows LoadLibrary and GetProcAddress. Maybe googling for libdl will find you some useful info. However, generally you won't need to use those functions directly, rather the compiler generates an import library containing the dynamic-linking code and you link statically with that (again just like Windows). Here is a good website that explains the basics of creating and using shared objects with gcc.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 911 posts

Posted 08 January 2007 - 10:34 AM

However, in case you do need the functions, here they are:


void *handle = dlopen("somelib.so", RTLD_LAZY);

void *function = dlsym(handle, "someFunction");

// Do some stuff with function

if(dlclose(handle) != 0)

    printf("some error");


"Stupid bug! You go squish now!!" - Homer Simpson

#4 TheNut

    Senior Member

  • Moderators
  • 1473 posts
  • LocationThornhill, ON

Posted 08 January 2007 - 12:08 PM

If you want to compile your code as a shared library, the easiest way is to get GCC to do all the dirty work for you (assuming you're using GCC). Export your classes or functions and compile them with argument -fPIC and link them with the argument -shared. Save them as .so (shared object) since this is how Linux names their "dlls". When you next compile your application, GCC will automatically link all the imported functions.

http://tldp.org/HOWT...-libraries.html
http://www.nutty.ca - Being a nut has its advantages.

#5 sybesis

    New Member

  • Members
  • Pip
  • 2 posts

Posted 09 January 2007 - 07:24 AM

Very cool.
I hope i'll be able to show some stuff here.

And yes i use GCC. :happy:

Thank you all





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users