Advertisement

Dynamic Libraries

Started by December 24, 2003 06:43 PM
0 comments, last by Krumble 20 years, 8 months ago
Hello, Over the last year and a bit I''ve been making the transition from Windows to Linux and I''m curious as to how to make something similar to a DLL that''s loaded at runtime (think plugin). I tried google, but I''m unsure what exactly to look for. Can anyone point me in the general direction of how to create .so files (I think that''s what I want), and how to load them into a program at runtime and call functions from them etc. Thanks
Kevin.
compile them with C linkage (extern "c" {} ) if they''re C++, and then build them with gcc with the -shared option. to output an .so.

then dlopen(the.so) and dlsym(my_func); and dlclose(ptr) and dlerror(read the man pages)

If you''re using C++, my reccomendation is to do something like

both:
class { ADT with interface definition. all virtual functions }

.so file:
class { derived }
NEW_CLASS { function that return a new derived_class }

thus instead of doing ''new derived'' (as would be natural if you compiled statically) you''d do a new_derived (which is a funciton pointer into the lib) and get the interface right out of that.

This topic is closed to new replies.

Advertisement