This repository demonstrates how to dynamically link to a "host" executable from a "plugin" shared library.
-
lib
— Contains agreet
function accepting a string. -
host
— "Host" executable that referencesgreet
in source and links tolib
statically, providing thegreet
symbol in its executable binary. -
plugin
— "Plugin" shared library that referencesgreet
in source but does not link tolib
at all, leaving thegreet
symbol undefined at compile time. At runtime,greet
will be accessible becauseplugin
is loaded intohost
, gaining access tohost
's symbols.
Run build.sh
to produce host
and plugin.dylib
in bin/
. Run host
and pass the path to the plugin as an argument:
$ bin/host bin/plugin.dylib
Hello, world!
You can move the host and the plugin to arbitrary locations and it will still work. You can also change the strings used for the greeting, and mix and match hosts and plugins.