www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Template issue?

reply "Kris" <fu bar.com> writes:
I understand there's some issue regarding the use of Template code from a 
library? The Boxer template comes to mind ~ something to do with debug vs 
non-debug compiles?

Could someone explain the issue, please? And how one might get around it?

Thx 
Nov 23 2005
parent reply Sean Kelly <sean f4.ca> writes:
Kris wrote:
 I understand there's some issue regarding the use of Template code from a 
 library? The Boxer template comes to mind ~ something to do with debug vs 
 non-debug compiles?
 
 Could someone explain the issue, please? And how one might get around it?
The issue I've encountered has to do with contracts and asserts. DMD generates function calls for this stuff, and since templates are generated when the client code is compiled, the client code may or may not expect these functions to exist during the linking phase. Probably not a big deal if you're willing to provide debug and release builds of your library, but this was a problem for Ares because it is linked implicitly. The workaround I used was to build modules containing template code without the -release flag set. This worked out fairly well for Ares because the modules containing template code only contain template code, so the result was an object file that contained only the compiler-generated contract and assert functions. Then when the client compiles the actual template code is generared according to whatever compiler options he specifies, which may include inlining and such, and the contract functions are available for linking should they be necessary. It's not an ideal solution, but it seems sufficient if you're willing to live with the template-only module rule. Sean
Nov 23 2005
parent "Kris" <fu bar.com> writes:
Very helpful.  Thanks, Sean.


"Sean Kelly" <sean f4.ca> wrote in message 
news:dm2i1m$1o4b$1 digitaldaemon.com...
 Kris wrote:
 I understand there's some issue regarding the use of Template code from a 
 library? The Boxer template comes to mind ~ something to do with debug vs 
 non-debug compiles?

 Could someone explain the issue, please? And how one might get around it?
The issue I've encountered has to do with contracts and asserts. DMD generates function calls for this stuff, and since templates are generated when the client code is compiled, the client code may or may not expect these functions to exist during the linking phase. Probably not a big deal if you're willing to provide debug and release builds of your library, but this was a problem for Ares because it is linked implicitly. The workaround I used was to build modules containing template code without the -release flag set. This worked out fairly well for Ares because the modules containing template code only contain template code, so the result was an object file that contained only the compiler-generated contract and assert functions. Then when the client compiles the actual template code is generared according to whatever compiler options he specifies, which may include inlining and such, and the contract functions are available for linking should they be necessary. It's not an ideal solution, but it seems sufficient if you're willing to live with the template-only module rule. Sean
Nov 23 2005