title: Linking C++ to static library; undefined reference errors
body: <p>I'm trying to link a small C++ test program, <code>main.o</code> to a 3rd party static library, but get some inexplicable <code>undefined reference</code> errors.</p>
  
  <p>Specifically:</p>
  
  <pre><code>g++  -o secoTest -lpthread  main.o  libEAPI.a
  main.o: In function `main':
  main.cpp:(.text+0x29fe): undefined reference to `EApiWDog_SetConfigAndStart(unsigned int, unsigned int, unsigned int, unsigned int, unsigned char, unsigned char, unsigned char)'
  main.cpp:(.text+0x33fc): undefined reference to `EApiSetCarrier(unsigned char)'
  main.o:main.cpp:(.text+0x3956): more undefined references to `EApiSetCarrier(unsigned char)' follow
  main.o: In function `main':
  main.cpp:(.text+0x3965): undefined reference to `EApiGPIOGetSerialCfg(unsigned char*)'
  main.cpp:(.text+0x3a0a): undefined reference to `EApiSetCarrier(unsigned char)'
  main.cpp:(.text+0x3a19): undefined reference to `EApiGPIOSetSerialCfg(unsigned char)'
  main.cpp:(.text+0x3adf): undefined reference to `EApiFanEnable(unsigned int, unsigned char)'
  main.cpp:(.text+0x3b83): undefined reference to `EApiFanDisable()'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>However, it seems the symbols <strong>are</strong> present in the library. For example:</p>
  
  <pre><code>nm --demangle libEAPI.a | grep EApiFanDisable
  00003c20 T EApiFanDisable
  </code></pre>
  
  <p>The strange thing is the symbols are not <strong>exactly</strong> the same. In <code>main.o</code> it is </p>
  
  <pre><code>nm --demangle main.o | grep EApiFanDisable
           U EApiFanDisable()
  </code></pre>
  
  <p>So one has <code>()</code> and one doesn't.</p>
  
  <p>Similarily,</p>
  
  <pre><code>nm --demangle main.o | grep EApiSetCarrier
           U EApiSetCarrier(unsigned char)
  nm --demangle libEAPI.a | grep EApiSetCarrier
  000015d0 T EApiSetCarrier
  </code></pre>
  
  <p>If I leave out the library altogether from the command line (eg, <code>g++  -o secoTest -lpthread  main.o</code>) it shows lots of errors as expected.  </p>
  
  <p><code>main.o</code> references external symbols with and with <code>()</code> [why?]:</p>
  
  <pre><code>     U EApiVgaSetBacklightEnable
       U EApiWDogStart
       U EApiWDogTrigger
       U EApiFanEnable(unsigned int, unsigned char)
       U EApiFanDisable()
       U EApiSetCarrier(unsigned char)
  </code></pre>
  
  <p>But the library has only symbols without <code>()</code> [why?]:</p>
  
  <pre><code>000020e0 T EApiVgaSetBacklightEnable
  000024e0 T EApiWDogStart
  000026f0 T EApiWDogTrigger
  00003c20 T EApiFanDisable
  00003bf0 T EApiFanEnable
  000015d0 T EApiSetCarrier
  </code></pre>
  
  <p>Would that be the reason for the undefined references?   How would I fix it?  Not sure where to look next...</p>
  
  <p>(I cannot modify the 3rd party library but have the header files.)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As lisyarus suggested, here is the <code>nm</code> without the <code>--demangle</code>.  Indeed, the symbols are different.  The g++ compiler (v4.4.7) generates a mangled symbol <em>for some symbols only</em> while the library always has plain symbols...  [why?]</p>
  
  <pre><code>nm libEAPI.a main.o | grep EApiWDogTrigger
  000026f0 T EApiWDogTrigger
           U EApiWDogTrigger
  nm libEAPI.a main.o | grep EApiSetCarrier
  000015d0 T EApiSetCarrier
           U _Z14EApiSetCarrierh
  </code></pre>