title: Discard unused functions in GCC
body: <p>I need some help for compiling with GCC under <a href="https://en.wikipedia.org/wiki/MinGW" rel="nofollow noreferrer">MinGW</a>.</p>
  <p>Say I have two files:</p>
  <ul>
  <li>File <em>a.c</em> contains two functions, <em>a1</em> and <em>a2</em></li>
  <li>File <em>b.c</em> contains two functions, <em>b1</em> and <em>b2</em>.</li>
  </ul>
  <p>Then I link the two objects into a shared library. The command used are like:</p>
  <pre class="lang-none prettyprint-override"><code>gcc -c a.c
  gcc -c b.c
  gcc -shared -Wl, --version-script v.ver -Wl, -Map=out.map -Wl, --strip-all -o mydll.dll a.o b.o
  </code></pre>
  <p>File <em>v.ver</em> looks like:</p>
  <pre class="lang-none prettyprint-override"><code>mylib {
     global: a1;
             a2;
     local: *;
  }
  </code></pre>
  <p>which is used to control which functions to be exported.</p>
  <p>By checking the mapfile I can see that the two functions in <em>b.c</em> are also included into the .text section of the DLL file.</p>
  <p>Because this DLL file only exports <em>a1</em> and <em>a2</em>, and <em>b1</em> and <em>b2</em> are only defined in <em>b.c</em>, but never used anywhere. Is there an option I could add in GCC or <a href="https://en.wikipedia.org/wiki/Linker_%28computing%29#GNU_linker" rel="nofollow noreferrer">ld</a> so that <em>b1</em> and <em>b2</em> are not built into the DLL file so that I can save some space in the DLL file?</p>