title: How to make C function dynamically exported
body: <p>My application works with static library which has extensions API. The API is able to call extension init function from the external shared library or from the "local" binary. That is I can include extension init function statically in to the main executable binary.</p>
  
  <p>The local function is searched by <code>dlsym</code> call and init function should be dynamically exported from the main binary. That is following <code>nm</code> call:</p>
  
  <pre><code>nm -CD &lt;binary&gt;
  </code></pre>
  
  <p>should list my init function.</p>
  
  <p>Let's assume init function has this signature:</p>
  
  <pre><code>int init_func(INIT_STRUCT *);
  </code></pre>
  
  <p>This function is not called directly - it is only supposed to be loaded by <code>dlsym</code> call.</p>
  
  <p>So I have two related question:</p>
  
  <ol>
  <li>how to force linker to not exclude this function from the generated binary?</li>
  <li>how to force compiler/linker to export this function dynamically?</li>
  </ol>
  
  <p>(I use <code>gcc</code> to compile and link my program)</p>