tags:

views:

159

answers:

2

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
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
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
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
+2  A: 
ephemient