title: Multiple definitions of same function in C++
body: <p>I am writing a library for neural nets. There are some necessary functions I needed so I separated them in a separate header file. I also provided the definition guards. I also included the header file in only one file but then also linker claims that there are multiple definitions of all the functions in the program.
  The library structure is as follows:</p>
  
  <pre><code>namespace maya:
       class neuron [neuron.hpp, neuron.cpp]
       class ffnet [ffnet.hpp, ffnet.cpp]
       struct connection [connection.hpp]
       functions [functions.hpp]
  </code></pre>
  
  <p>the functions header file is written something like this:</p>
  
  <p><code>#ifndef FUNCTIONS_HPP</code><br>
  <code>#define FUNCTIONS_HPP</code><br>
  <code>// some functions here</code><br>
  <code>double random_double(){//some code}</code><br>
  <code>#endif</code></p>
  
  <p>this functions.hpp file is included only one in neuron.hpp and since ffnet is dependent on neuron, I included neuron.hpp in ffnet only once. This ffnet.hpp is included in main.cpp only once. main.cpp is file that I use for testing my library.</p>
  
  <p>this linker throws error something like this:<br>
  <code>/usr/bin/ld: /tmp/ccN7ywby.o: in function `maya::random_double()': 
  neuron.cpp:(.text+0x0): multiple definition of maya::random_double()'; /tmp/ccvDr1aG.o:main.cpp:(.text+0x0): first defined here</code></p>
  
  <p><code>/usr/bin/ld: /tmp/cc66mBIr.o: in function `maya::random_double()':``
  ffnet.cpp:(.text+0x0): multiple definition of `maya::random_double()'; /tmp/ccvDr1aG.o:main.cpp:(.text+0x0): first defined here</code></p>
  
  <p>Also I compiled my program using :<br>
  <code>g++ main.cpp neuron.cpp ffnet.cpp -o net</code></p>
  
  <p>I don't think this will be needed but just in case : <br>
  <code>$ uname -a</code><br>
  <code>Linux brightprogrammer 4.19.0-kali3-amd64 #1 SMP Debian 4.19.20-1kali1 (2019-02-14) x86_64 GNU/Linux</code></p>