Project

General

Profile

CppModules » History » Revision 2

Revision 1 (hazzadous, 2009-04-03 12:20) → Revision 2/14 (hazzadous, 2009-04-03 15:13)

h1. Including C++ libraries and code within your lighttpd modules 

 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. 

 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. ) CppModules