|Posted by Sean Kelly||PermalinkReply|
DMD has some issues with template code compiled into libraries. Specifically, if that template code uses DBC and the library was compiled with the -release flag set, any code building against that template module in debug mode will generate linker errors. From what I can tell, it seems that DMD generates function calls for contract validation. These functions are not generated during the library build because of the -release flag, but as templates as dynamically generated, any end-user application building in debug-mode will attempt to link to these nonexistent functions.
I've found a temporary fix for Ares that seems to work just fine for all-template modules: build those particular files in debug mode and link the obj files into the library. Since templates are generated dynamically, all the obj file will contain are the DBC functions--the actual template functions will be generated dynamically using whatever flags the user specifies. So the only overhead is the definition of these DBC functions in the static library. The obvious problem is that these modules can only contain template code, as we want everything else to build using the standard library options.
I'm not sure how best to handle this, but perhaps DMD could offer a flag to generate contract functions for templates even if -release is set? For the moment, I don't mind splitting up my modules based on content, but this isn't a long-term solution.