title: Undefined reference error but symbol existing in the library
body: <p>I get an <code>undefined reference</code> error for the example below. I have seen lots of questions that relate to this issue but believe I gave a stripped, reproducible, conceptual example as opposed specific issues in other questions,</p>
  
  <p>dynlib.h:</p>
  
  <pre><code>void printMe_dyn();
  </code></pre>
  
  <p>dynlib.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "dynlib.h"
  
  void printMe_dyn() {
    printf("I am execuded from a dynamic lib");
  }
  </code></pre>
  
  <p>myapp.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "dynlib.h"
  
  int main() 
  {
      printMe_dyn();
      return 0;
  }
  </code></pre>
  
  <p>Build steps:</p>
  
  <pre><code>gcc -Wall -fpic -c dynlib.c
  gcc -shared -o libdynlib.so dynlib.o
  gcc -Wall -L. -ldynlib myapp.c -o myapp
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>/tmp/ccwb6Fnv.o: In function `main':
  myapp.c:(.text+0xa): undefined reference to `printMe_dyn'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>Proof that the symbol is in the library:</p>
  
  <pre><code>nm libdynlib.so | grep printMe_dyn
  00000000000006e0 T printMe_dyn
  </code></pre>
  
  <ol>
  <li><em>Am I using the correct compiler flags for building the dynamic
  library?</em> </li>
  <li><em>Is the proof I've presented really an unambiguous proof?</em></li>
  <li><em>What other approach could be taken to diagnose the issue?</em></li>
  </ol>