title: How to apply -fvisibility option to symbols in static libraries?
body: <p>I have a shared library project that is built from 4 static libraries (<code>.a</code>) and one object (<code>.o</code>) file. I am trying to add the <code>-fvisibility=hidden</code> option to restrict symbols in the output to only those that I mark in the source with an __attribute__.</p>
  
  <p>I've added the <code>-fvisibility=hidden</code> option to the compile options for the <code>.so</code> project (which covers the <code>.o</code> file) and for the <code>.a</code> projects.</p>
  
  <p>The symbols in the object file are removed as expected from the final <code>.so</code>. However the symbols from the <code>.a</code> projects are all still in the final <code>.so</code> file. Adding the <code>-fvisibility=hidden</code> option to the <code>.so</code> link command has no effect.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>My purpose here is to remove from the <code>.so</code> all symbols except the interface functions to the library.</p>
  
  <p>EDIT: I actually used a <a href="http://sourceware.org/ml/binutils/2000-05/msg00305.html" rel="noreferrer">version map</a> to solve this for now. However it requires continued maintenance of the version script as external symbols change. Accepted answer has a better idea.</p>