title: Library design: allow user to decide between "header-only" and dynamically linked?
body: <p>I have created several C++ libraries that currently are <strong>header-only</strong>. Both the interface and the implementation of my classes are written in the same <code>.hpp</code> file.</p>
  
  <p>I've recently started thinking that this kind of design is not very good:</p>
  
  <ol>
  <li>If the user wants to compile the library and link it dynamically, he/she can't.</li>
  <li>Changing a single line of code requires full recompilation of existing projects that depend on the library.</li>
  </ol>
  
  <p>I really enjoy the aspects of header-only libraries though: all functions get potentially inlined and they're very very easy to include in your projects - no need to compile/link anything, just a simple <code>#include</code> directive.</p>
  
  <p>Is it possible to get the best of both worlds? I mean - allowing the user to choose how he/she wants to use the library. It would also speed up development, as I'd work on the library in "dynamically-linking mode" to avoid absurd compilation times, and release my finished products in "header-only mode" to maximize performance.</p>
  
  <p>The first logical step is dividing interface and implementation in <code>.hpp</code> and <code>.inl</code> files.</p>
  
  <p>I'm not sure how to go forward, though. I've seen many libraries prepend <code>LIBRARY_API</code> macros to their function/class declarations - maybe something similar would be needed to allow the user to choose?</p>
  
  <hr>
  
  <p>All of my library functions are prefixed with the <code>inline</code> keyword, to avoid <em>"multiple definition of..."</em> errors. I assume the keyword would be replaced by a <code>LIBRARY_INLINE</code> macro in the <code>.inl</code> files? The macro would resolve to <code>inline</code> for "header-only mode", and to nothing for the "dynamically-linking mode".</p>