title: When look up symbol, the program doesn't search from the correct library
body: <p>I'm adding two classes and libraries to a system, <code>parent.so</code> and <code>child.so</code> deriving from it. </p>
  
  <p>The problem is when the program is loading <code>child.so</code> it cannot find parent's virtual function's definition from <code>parent.so</code>. </p>
  
  <p>What happens,</p>
  
  <p><code>nm -D child.so</code> will gives something like (I just changed the names)</p>
  
  <p><code>U _ZN12PARENT15virtualFunctionEv</code></p>
  
  <hr>
  
  <p>The program will crash running</p>
  
  <pre><code>_handle = dlopen(filename, RTLD_NOW|RTLD_GLOBAL); //filename is child.so
  </code></pre>
  
  <p>it'll give an error with <code>LD_DEBUG = libs</code></p>
  
  <pre><code>symbol lookup error: undefined symbol: _ZN12PARENT15virtualFunctionEv (fatal)
  </code></pre>
  
  <p>The thing I cannot explain is, I tried <code>LD_DEBUG = symbols</code> using GDB, when running <code>dlopen</code>, the log shows it tried to look up basically in all libaries in the system except <code>parent.so</code>, where the symbol is defined. But from libs log <code>parent.so</code> is already loaded and code is run, and it is at the same path of all other libraries. </p>
  
  <pre><code> ......
   27510:     symbol=_ZN12PARENT15virtualFunctionEv;  lookup in file=/lib/tls/libm.so.6
   27510:     symbol=_ZN12PARENT15virtualFunctionEv;  lookup in file=/lib/tls/libc.so.6
   27510:     symbol=_ZN12PARENT15virtualFunctionEv;  lookup in file=/lib/ld-linux.so.2
   27510:     child.so: error: symbol lookup error: undefined symbol: _ZN12PARENT15virtualFunctionEv(fatal)
  </code></pre>
  
  <p>How the program or system is managing which library to look for a symbol's definition?</p>
  
  <p>I'm new to Linux, can anybody point me some directions to work on?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The command used to generate <code>parent.so</code> file is</p>
  
  <pre><code>c++  -shared  -o parent.so parent.o
  </code></pre>
  
  <p>Similar for <code>child.so</code>. Is any information missing for linking here? Looks like child is only including parent's header file.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>After another test, calling </p>
  
  <pre><code>_handle = dlopen("parent.so", RTLD_NOW|RTLD_GLOBAL);
  </code></pre>
  
  <p>before the crashing line will solve the problem, which I think means originally <code>parent.so</code> was not loaded. But I'm still not very clear about the cause.</p>