title: Strip specific symbols from DLL
body: <p>I have created a Win32-DLL using MSVC 2010 that contains unwanted exported C++ symbols. I'm using a module definition file (<code>.def</code>) and <code>__stdcall</code> convention for specific functions that I want to export. However, due to the fact that I am also using Boost Serialization there is a ton of exported C++ symbols from Boost. These symbols are exported by Boost due to this fact (found <a href="http://lists.boost.org/boost-users/2010/09/62996.php" rel="nofollow">here</a>):</p>
  
  <blockquote>
    <blockquote>
      <p>I am using boost::serialization from 1.44.0. One thing that I noticed
      is that linking statically to the serialization libs will add several
      hundred exports in the final exe file that I get. Using <code>dumpbin
      /exports my_program.exe</code></p>
    </blockquote>
    
    <p>These functions are not explicity called from the library. But they
    ARE called as part of the serialization process. Its just that MSVC
    doesn't see them. So when you compile for release, The MSVC Linker
    strips them out and the program won't work anymore. In order to work
    around this, these functions are explicitly exported. This prevents
    MSVC from stripping them out. For more information see
    force_include.hpp</p>
  </blockquote>
  
  <p>Exported symbols (excerpt):</p>
  
  <pre><code>class boost::archive::detail::extra_detail::map&lt;class boost::archive::binary_oarchive&gt; &amp; &gt;boost::serialization::singleton&lt;class boost::archive::detail::extra_detail::map&lt;class boost::archive::binary_oarchive&gt; &gt;::get_instance(void)'::`2'::`local static guard'{2}'
  </code></pre>
  
  <p>You can recreate the situation by creating a DLL project and include Boost (link against <code>libboost_serialization-vc100-mt-gd-1_55.lib</code>):</p>
  
  <pre><code>#include &lt;boost/archive/binary_oarchive.hpp&gt;
  #include &lt;fstream&gt;
  
  extern "C" int __stdcall test();
  
  int __stdcall test() {
      std::fstream stream;
      boost::archive::binary_oarchive o(stream, boost::archive::no_header);
      return 1;
  }
  </code></pre>
  
  <p>I tested the GNU utility <a href="https://sourceware.org/binutils/docs/binutils/strip.html" rel="nofollow"><code>strip</code> from <code>binutils</code></a>. However, it seems it always removes all symbols. E.g. using this command</p>
  
  <pre><code>strip --strip-symbol=test DllBoostTest.dll -o test.dll
  </code></pre>
  
  <p>This simple test does not work. It should remove only the test symbol. Unfortunately, it also removes all symbols. Also using wildcards and <code>-N</code> does not work as it removes all exports, too.</p>
  
  <p><em>So is there a way to remove all unwanted boost C++ symbols?</em> Say, remove all symbols with "boost" text in it?</p>
  
  <p>If you need more information, I'm happy to provide it.</p>
  
  <hr>
  
  <p><strong>Note:</strong> This is not about debugging or PDB files!</p>