title: How to avoid multiple definition linking error?
body: <p>Beside moving the <code>hello()</code> function into another source (.cpp) file or renaming the function. Is there any other methods to avoid the linking error?</p>
  
  <p><strong>staticLibA.h</strong></p>
  
  <pre><code>#ifndef _STATIC_LIBA_HEADER
  #define _STATIC_LIBA_HEADER
  
  int hello(void);
  int hello_staticLibA_only(void);
  
  #endif
  </code></pre>
  
  <p><strong>staticLibA.cpp</strong></p>
  
  <pre><code>#include "staticLibA.h"
  
  int hello(void)
  {
      printf("\nI'm in staticLibA\n");
      return 0;
  }
  
  int hello_staticLibA_only(void)
  {
      printf("\nstaticLibA: hello_staticLibA_only\n");
      return 0;
  }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>g++ -c -Wall -fPIC -m32 -o staticLibA.o staticLibA.cpp
  ar -cvq ../libstaticLibA.a staticLibA.o
  a - staticLibA.o
  </code></pre>
  
  <p><strong>staticLibB.h</strong></p>
  
  <pre><code>#ifndef _STATIC_LIBB_HEADER
  #define _STATIC_LIBB_HEADER
  
  int hello(void);
  int hello_staticLibB_only(void);
  
  #endif
  </code></pre>
  
  <p><strong>staticLibB.cpp</strong></p>
  
  <pre><code>#include "staticLibB.h"
  
  int hello(void)
  {
      printf("\nI'm in staticLibB\n");
      return 0;
  }
  
  int hello_staticLibB_only(void)
  {
      printf("\nstaticLibB: hello_staticLibB_only\n");
      return 0;
  }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>g++ -c -Wall -fPIC -m32 -o staticLibB.o staticLibB.cpp 
  ar -cvq ../libstaticLibB.a staticLibB.o 
  a - staticLibB.o
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>extern int hello(void);
  extern int hello_staticLibA_only(void);
  extern int hello_staticLibB_only(void);
  
  int main(void)
  {
    hello();
    hello_staticLibA_only();
    hello_staticLibB_only();
    return 0;
  }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>g++ -c  -o main.o main.cpp
  g++ -o multipleLibsTest main.o  -L. -lstaticLibA -lstaticLibB -lstaticLibC -ldl -lpthread -lrt
  ./libstaticLibB.a(staticLibB.o): In function `hello()':
  staticLibB.cpp:(.text+0x0): multiple definition of `hello()'
  ./libstaticLibA.a(staticLibA.o):staticLibA.cpp:(.text+0x0): first defined here
  collect2: ld returned 1 exit status
  make: *** [multipleLibsTest] Error 1
  </code></pre>