title: With GCC, how do I export only certain functions in a static library?
body: <p>I've created a static library in GCC, but I'd like to hide most of the symbols.</p>
  
  <p>For example, test1.c:</p>
  
  <pre><code>extern void test2(void);
  void test1(void) {
    printf("test1: ");
    test2();
  }
  </code></pre>
  
  <p>test2.c:</p>
  
  <pre><code>extern void test1(void);
  void test2(void) {
    printf("test2\n");
  }
  </code></pre>
  
  <p>library_api.c:</p>
  
  <pre><code>extern void test1(void);
  extern void test2(void);
  void library_api(void) {
    test1();
    test2();
  }
  </code></pre>
  
  <p>Now compile with:</p>
  
  <pre><code>gcc -c test1.c -o test1.o
  gcc -c test2.c -o test2.o
  gcc -c library_api.c -o library_api.o
  ar rcs libapi.a test1.o test2.o library_api.o
  </code></pre>
  
  <p>How do I get only the "library_api()" function to show up for:</p>
  
  <pre><code>nm libapi.a
  </code></pre>
  
  <p>instead of the functions "test1()", "test2()", and "library_api()"?  In other words, how do I hide "test1()" and "test2()" from showing up and being callable to external users of libapi.a?  I don't want external users to know anything about internal test functions.</p>