title: Linking archives (.a) into shared object (.so)
body: <p>I'm compiling some shared objects file into an <code>archive.a</code>:</p>
  
  <pre><code>$ g++ -c -Iinclude/ -fPIC -O0 -o object1.o source1.cpp
  $ g++ -c -Iinclude/ -fPIC -O0 -o object2.o source2.cpp
  $ ar rvs archive.a object1.o object2.o
  r - object1.o
  r - object2.o
  </code></pre>
  
  <p>So far so good. The resulting <code>archive.a</code> has a good size of some KB. A dump with <code>nm</code> shows that the corresponding object-files are contained within the files.</p>
  
  <p>Now I'm wanting to compile several of these archives into a shared object file.</p>
  
  <pre><code>g++ -g -O0 -Iinclude/ -I/usr/include/somelibrary -shared -o libLibrary.so archive1.a archive2.a
  </code></pre>
  
  <p>The result is that my resulting library file is nearly <strong>empty</strong>:</p>
  
  <pre><code>$ nm -D libLibrary.so
                   w _Jv_RegisterClasses
  0000000000201010 A __bss_start
                   w __cxa_finalize
                   w __gmon_start__
  0000000000201010 A _edata
  0000000000201020 A _end
  0000000000000578 T _fini
  0000000000000430 T _init
  </code></pre>
  
  <p>Any idea what I'm doing wrong?</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>When I try the switch <code>-Wl,--whole-archive</code>, following happens:</p>
  
  <pre><code>/usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
  (.text+0xd): undefined reference to `__init_array_end'
  /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS): relocation R_X86_64_PC32 against undefined hidden symbol `__init_array_end' can not be used when making a shared object
  /usr/bin/ld: final link failed: Bad value
  collect2: ld returned 1 exit status
  make: *** [libKeynect.so] Error 1
  </code></pre>