title: Symbol is lost after linking shared library
body: <p>Consider the two files listed below:</p>
  
  <p>file <code>a.c</code></p>
  
  <pre><code>extern int foovar;
  int foobarize() {
      return foovar * foovar;
  }
  </code></pre>
  
  <p>and file <code>b.c</code></p>
  
  <pre><code>int foovar = 10;
  </code></pre>
  
  <p>I compile the static library <code>liba.a</code> and the shared library <code>libb.so</code> as follows:</p>
  
  <pre><code># liba.a
  gcc -fPIC -c a.c -o a.o
  ar cr liba.a a.o
  ranlib liba.a
  
  # libb.so
  gcc -fPIC -c b.c -o b.o
  gcc -fPIC -shared -Wl,-soname,libb.so -o libb.so b.o liba.a
  </code></pre>
  
  <p>Note that the function <code>foobarize</code> defined in <code>a.c</code> <em>is</em> present in <code>liba.a</code> but it <em>isn't</em> present in <code>libb.so</code>. I can guarantee that by issuing the <code>nm</code> program:</p>
  
  <pre><code>$ nm liba.a
  
  a.o:
  0000000000000000 T foobarize
                   U foovar
                   U _GLOBAL_OFFSET_TABLE_
  
  $ nm libb.so
  000000000020088c B __bss_start
  000000000020088c b completed.6617
                   w __cxa_finalize@@GLIBC_2.2.5
  0000000000000530 t deregister_tm_clones
  00000000000005c0 t __do_global_dtors_aux
  0000000000200650 t __do_global_dtors_aux_fini_array_entry
  0000000000200880 d __dso_handle
  0000000000200660 d _DYNAMIC
  000000000020088c D _edata
  0000000000200890 B _end
  0000000000000630 T _fini
  0000000000200888 D foovar
  0000000000000600 t frame_dummy
  0000000000200648 t __frame_dummy_init_array_entry
  0000000000000640 r __FRAME_END__
  0000000000200858 d _GLOBAL_OFFSET_TABLE_
                   w __gmon_start__
  00000000000004d8 T _init
                   w _ITM_deregisterTMCloneTable
                   w _ITM_registerTMCloneTable
  0000000000200658 d __JCR_END__
  0000000000200658 d __JCR_LIST__
                   w _Jv_RegisterClasses
  0000000000000570 t register_tm_clones
  0000000000200890 d __TMC_END__
  </code></pre>
  
  <p>How can I get the <code>foobarize</code> function in the <code>libb.so</code> shared library?</p>