I'm reading through the manpage for dlopen and friends on FreeBSD. I'm working on a cross-platform application that is using shared libraries for loadable plugins. I've never done this before, but I think I have a decent grasp of how it works. The manpage mentions dlsym(), which appears to be the common means of getting a function pointer from a shared library, and dlfunc(), which supposedly avoids compiler complaints about casting a void* to a function pointer. Is there a reason dlsym() is more common (portability?) ? I'm wondering whether I should use dlfunc() to avoid compiler problems, or use dlsym(). Is dlfunc() portable?
+1
A:
When you say cross platform, do you mean cross-POSIX platforms or do you need Windows support too?
If you're working in C++ you could have a look at the Boost.Extension proposal code. This takes care of Windows vs. UNIX portability.
If you're looking for UNIX-only advice, have a look at the Single UNIX Specification.
As far as I know, dlsym is the standard UNIX way to do things. Windows has an equivalent but completely different way of doing things.
Michael van der Westhuizen
2009-07-17 16:01:00
Cross-platform in this case is cross-POSIX. I have very little desire to begin digging into the dark depths of Windows programming.
Edward Amsden
2009-07-17 16:35:23
HP-UX - at least on PA-RISC machines (getting towards archaic, I know) has a separate system. I think the IA64 machines use dlsym()/dlopen().
Jonathan Leffler
2009-08-30 18:49:51
Yep, 32 bit HP-UX on PA-RISC uses the SOM format (shlib_* functions), which is a bit nasty (and apparently doesn't do reference counting). 64 bit HP-UX on PA-RISC uses ELF, as do both 32 and 64 bit HP-UX on ia64 - these have the more sane dl* interfaces.
Michael van der Westhuizen
2009-08-31 06:44:49