title: GCC: --whole-archive and --no-whole-archive options
body: <p>I am creating a shared object library from two <code>*.a</code> (static libraries) using GCC. I referred these articles:</p>
  <ol>
  <li><a href="https://stackoverflow.com/questions/14116420/how-to-force-gcc-to-link-an-unused-static-library">How to force gcc to link an unused static library</a></li>
  <li><a href="https://stackoverflow.com/questions/2763988/how-to-include-all-objects-of-an-archive-in-a-shared-object">How to include all objects of an archive in a shared object?</a></li>
  </ol>
  <p>and created a command line as:</p>
  <pre><code>gcc -shared -o libmain.so main.o  -Wl,--whole-archive -lgdiplus -lsqlite3 -Wl,--no-whole-archive
  </code></pre>
  <p>Here <code>main.o</code> is compiled with <code>-fPIC</code> option and used for linking to create final output file called <code>libmain.so</code>. But when I checked my output, it seems to be empty:</p>
  <pre><code>$&gt;# nm libmain.so
  00000000002005d0 a _DYNAMIC
  0000000000200788 a _GLOBAL_OFFSET_TABLE_
                   w _Jv_RegisterClasses
  00000000002005a8 d __CTOR_END__
  00000000002005a0 d __CTOR_LIST__
  00000000002005b8 d __DTOR_END__
  00000000002005b0 d __DTOR_LIST__
  0000000000000598 r __FRAME_END__
  00000000002005c0 d __JCR_END__
  00000000002005c0 d __JCR_LIST__
  00000000002007a8 A __bss_start
                   w __cxa_finalize@@GLIBC_2.2.5
  0000000000000500 t __do_global_ctors_aux
  0000000000000440 t __do_global_dtors_aux
  00000000002005c8 d __dso_handle
                   w __gmon_start__
  00000000002007a8 A _edata
  00000000002007b8 A _end
  0000000000000538 T _fini
  00000000000003e0 T _init
  0000000000000420 t call_gmon_start
  00000000002007b0 b completed.6145
  00000000002007a8 b dtor_idx.6147
  00000000000004ec T foo
  00000000000004c0 t frame_dummy
  </code></pre>
  <p>Ideally this should contain all the symbols from both <code>*.a files</code>, right?</p>
  <p>Can anybody guide what is wrong here? I am using RHEL 5.5 x64 and GCC 4.1.2.</p>
  <p>Thanks,
  Omkar</p>