Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a library dynamically in Linux or OSX?

Tags:

c++

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

like image 501
jmasterx Avatar asked Jan 10 '11 21:01

jmasterx


2 Answers

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

like image 152
David Heffernan Avatar answered Sep 29 '22 03:09

David Heffernan


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."

like image 33
EmeryBerger Avatar answered Sep 29 '22 03:09

EmeryBerger