title: C++ Linking one library through the other
body: <p>libA.so links to libB.so </p>
  
  <p>main links to libB.so but it can't access symbols of libA.so. Why? Is there a way i can make symbols of libA.so visible to main through libB.so</p>
  
  <pre><code>cat a.cc 
  #include&lt;iostream&gt;
  void hello() {
     return;
  }
  
  cat  b.cc
  #include &lt;iostream&gt;
  void goodbye() {
    return;
  }
  
  
  cat c.cc m
  #include&lt;iostream&gt;
  void goodbye();
  void hello();
  void tc() {
    goodbye();
    hello();
  }
  
  
  cat main.cc
  #include&lt;iostream&gt;
  void hello();
  void goodbye();
  int main() {
     hello();
  }
  </code></pre>
  
  <p>Not sure why this isn't working, how can i make it work?</p>
  
  <pre><code>g++ -fPIC -c a.cc b.cc 
  g++ a.o b.o -shared -o libA.so
  
  
  g++ -fPIC -c c.cc
  g++ c.o -shared -lA -L. -o libB.so 
  
  g++ main.cc -lA -L.
  g++ main.cc -lB -L.
  /tmp/cci2foLo.o: undefined reference to symbol '_Z5hellov'
  ./libA.so: error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  
  ldd libB.so 
  linux-vdso.so.1 =&gt;  (0x00007fffa733d000)
  libA.so =&gt; ./libA.so (0x00002b0f9a92a000)
  libstdc++.so.6 =&gt; /usr/lib64/libstdc++.so.6 (0x00002b0f9ab5e000)
  libm.so.6 =&gt; /lib64/libm.so.6 (0x00002b0f9ae64000)
  libgcc_s.so.1 =&gt; /lib64/libgcc_s.so.1 (0x00002b0f9b0e8000)
  libc.so.6 =&gt; /lib64/libc.so.6 (0x00002b0f9b2ff000)
  /lib64/ld-linux-x86-64.so.2 (0x00002b0f9a504000)
  </code></pre>
  
  <p>How can i link main to A through B?</p>