CppModules » History » Revision 3

« Previous | Revision 3/14 (diff) | Next »
hazzadous, 2009-04-03 15:41

Including C++ libraries and code within your lighttpd modules

Seeing in to the plugin
To load compiled modules, lighttpd needs a few things. Its point of entry to your code is the plugin_init function, which will be responsible for setting up plugin info like name, version etc. as well as other hooks into your plugin like init, the handlers etc. To access plugin_init, lighttpd looks for the C style symbol in your binary ( i.e. mod_rewrite_plugin_init ). As we have to compile with C++ support, we need to tell the compiler explicitly to use the C style name for this function so lighttpd can access it.

Setting up hooks
Once we can call plugin_init, and plugin has been passed into our module, we have to set up the hooks. Problem here is that these hooks in the plugin data structure are C style function pointers. There is no guarantee that it will have the same calling conventions as a C++ function pointer (will vary from compiler to compiler). To be totally accurate any function we choose to point these at should use the same calling conventions.

To tell your C++ compiler to use C symbol names and calling conventions, use extern "C" { /*...*/ } around the function prototypes for plugin_init and your hook functions. ( you can probably get away with omitting it from the hooks, but you may get unexpected results with some compilers. )

Updated by hazzadous about 14 years ago · 3 revisions