24

I know in Windows you would do something like LoadLibrary and then set your function pointer with GetProcAddress,

But how would something similar be done in Linux or OSX? The reason being is that I want to develop a plug in system for my X platform application.

Thanks

4 Answers 4

44

You are looking for dlopen (analogous to LoadLibrary), dlclose (analogous to FreeLibrary) and dlsym (analogous to GetProcAddress).

Sign up to request clarification or add additional context in comments.

Comments

15

You can use dlopen and friends on both Linux and Mac OS X (this Mac man page should work for both). Note, however, that you need to be careful not to mix 32-bit and 64-bit code and libraries; on the Mac, just make sure that the libraries are "universal binaries."

3 Comments

Does you comment about "universal binaries" apply to both Linux and Mac? Might be worth clarifying.
As far as I know, there is no generally-available fat binary scheme for Linux - yet ("universal binary" is Apple parlance for a fat binary). See en.wikipedia.org/wiki/…
@David - this dismissive letter from Ulrich Drepper (surprise!) makes it highly unlikely that Linux will support fat binaries until Hell freezes over...redhat.com/archives/fedora-devel-list/2009-October/…
6

In Linux you use dlopen() (open library), dlsym() (look up a symbol (=function or value, usually)) and friends: http://linux.die.net/man/3/dlopen

I hear it works the same way on OS X, but I have no experience with that.

Comments

3

The POSIX equivalents are dlopen and dlsym. I know Linux has them, and I would be surprised if OS X does not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.