<html> <head> <!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc --> <title>Reducing Compiling Time</title> <link rel="stylesheet" href="theme/style.css" type="text/css"> <link rel="prev" href="extending_wrapped_objects_in_python.html"> </head> <body> <table width="100%" height="48" border="0" cellspacing="2"> <tr> <td><img src="theme/c%2B%2Bboost.gif"> </td> <td width="85%"> <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Reducing Compiling Time</b></font> </td> </tr> </table> <br> <table border="0"> <tr> <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td> <td width="30"><a href="extending_wrapped_objects_in_python.html"><img src="theme/l_arr.gif" border="0"></a></td> <td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td> </tr> </table> <p> If you have ever exported a lot of classes, you know that it takes quite a good time to compile the Boost.Python wrappers. Plus the memory consumption can easily become too high. If this is causing you problems, you can split the class_ definitions in multiple files:</p> <code><pre> <span class=comment>/* file point.cpp */ </span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>point</span><span class=special>.</span><span class=identifier>h</span><span class=special>> </span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>> </span><span class=keyword>void </span><span class=identifier>export_point</span><span class=special>() { </span><span class=identifier>class_</span><span class=special><</span><span class=identifier>point</span><span class=special>>(</span><span class=string>"point"</span><span class=special>)...; } /* </span><span class=identifier>file </span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/ </span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>h</span><span class=special>> </span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>> </span><span class=keyword>void </span><span class=identifier>export_triangle</span><span class=special>() { </span><span class=identifier>class_</span><span class=special><</span><span class=identifier>triangle</span><span class=special>>(</span><span class=string>"triangle"</span><span class=special>)...; } </span></pre></code> <p> Now you create a file <tt>main.cpp</tt>, which contains the <tt>BOOST_PYTHON_MODULE</tt> macro, and call the various export functions inside it. </p> <code><pre> <span class=keyword>void </span><span class=identifier>export_point</span><span class=special>(); </span><span class=keyword>void </span><span class=identifier>export_triangle</span><span class=special>(); </span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>) { </span><span class=identifier>export_point</span><span class=special>(); </span><span class=identifier>export_triangle</span><span class=special>(); } </span></pre></code> <p> Compiling and linking together all this files produces the same result as the usual approach:</p> <code><pre> <span class=preprocessor>#include </span><span class=special><</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>> </span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>point</span><span class=special>.</span><span class=identifier>h</span><span class=special>> </span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>h</span><span class=special>> </span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>) { </span><span class=identifier>class_</span><span class=special><</span><span class=identifier>point</span><span class=special>>(</span><span class=string>"point"</span><span class=special>)...; </span><span class=identifier>class_</span><span class=special><</span><span class=identifier>triangle</span><span class=special>>(</span><span class=string>"triangle"</span><span class=special>)...; } </span></pre></code> <p> but the memory is kept under control. </p> <p> This method is recommended too if you are developing the C++ library and exporting it to Python at the same time: changes in a class will only demand the compilation of a single cpp, instead of the entire wrapper code.</p> <table width="80%" border="0" align="center"> <tr> <td class="note_box"> <img src="theme/note.gif"></img> If you're exporting your classes with <a href="../../../pyste/index.html"> Pyste</a>, take a look at the <tt>--multiple</tt> option, that generates the wrappers in various files as demonstrated here. </td> </tr> </table> <table width="80%" border="0" align="center"> <tr> <td class="note_box"> <img src="theme/note.gif"></img> This method is useful too if you are getting the error message <i>"fatal error C1204:Compiler limit:internal structure overflow"</i> when compiling a large source file, as explained in the <a href="../../v2/faq.html#c1204"> FAQ</a>. </td> </tr> </table> <table border="0"> <tr> <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td> <td width="30"><a href="extending_wrapped_objects_in_python.html"><img src="theme/l_arr.gif" border="0"></a></td> <td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td> </tr> </table> <br> <hr size="1"><p class="copyright">Copyright © 2002-2003 David Abrahams<br>Copyright © 2002-2003 Joel de Guzman<br><br> <font size="2">Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose. </font> </p> </body> </html>