title: How to limit the visibility of an exported symbol?
body: <p>I'm compiling and archiving a library (call it <code>libbar.a</code>). The key translation units in that library use a function <code>void foo()</code> defined (non-statically) in a <code>foo.cpp</code> which also gets compiled and put in the library. </p>
  
  <p>I want to avoid this <code>void foo()</code> clashing with other symbols elsewhere in my codebase (which uses that library). Now, you could say - just don't include a header which declares <code>void foo()</code>; but - what if I actually do use the same <code>void foo()</code> elsewhere? Even though it's more efficient to just have it once in my entire codebase, I actually want whoever uses the library to be oblivious to the implementation detail of <code>void foo()</code> being used internally. So - I want for nobody to be able to look up that symbol in <code>libbar.a</code>, but for the code within <code>libbar.a</code> to still be able to use it.</p>
  
  <p>How can I achieve this?</p>
  
  <p>Notes:</p>
  
  <ul>
  <li>The code (both for <code>foo</code> and my library) is C and/or C++. Answers assuming it's C-only or C++-only are also relevant.</li>
  <li>I realize that if I change the name (e.g. to <code>void bar_foo()</code>), or put <code>void foo()</code> into a namespace, that could have the desired effect. But I need to not do that, i.e. I need to keep using the same code for <code>void foo()</code> with no changes. I'm only willing to change things in library code which uses <code>void foo()</code> and in the build mechanism.</li>
  <li>I'm working with gcc on Linux; I'm hoping something which works with clang or is compiler-agnostic, though. I also automate my build with CMake, but don't bother writing CMake code  - just say what you want the build system to do in general terms.</li>
  </ul>