Undefined reference to a function when linking with g++
<p>I am trying to link several object files and I am getting 3 undefined reference to a function errors. </p>

<p>inputtest.cpp</p>

<pre><code>//test of input methods

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;


#include "Vector.h"
#include "Particle.h"
#include "read_particle_input.h"
#include "User_input.h"
#include "Particle_vector.h"

using namespace std;
using namespace berger_DEM;

int main() {

    Particle_vector particles;
    User_input input_data;

    read_particle_input(particles, input_data);

    cout &lt;&lt;endl&lt;&lt; particles.getpart(1).rho()&lt;&lt;endl&lt;&lt;particles.getpart(1).radius()&lt;&lt;endl;

    return 0;
}
</code></pre>

<p>I am linking it with 5 object files with the names found in the ".h" files(just .o files compiled from .cpp files of the same name). One of the errors I receive is </p>

<blockquote>
  <p>undefined reference to 'berger_DEM::read_particle_input(berger_DEM::Particle_vector&amp;, berger_DEM::User_input&amp;)</p>
</blockquote>

<p>note that this function has a prototype in read_particle_input.h and is implemented in read_particle_input.o. I am also getting two other undefined references, but I believe they are the same issue and if i can solve this one, the same solution should work for those two.</p>

<p>prototype:</p>

<pre><code>namespace berger_DEM
{   
    void read_particle_input(Particle_vector&amp;,User_input&amp;);
}
</code></pre>

<p>implementation:
//method to read in particle_input.dat</p>

<pre><code>void read_particle_input(Particle_vector &amp; particles, User_input &amp; input_data) 
{
    //define local variables
    Vector velocity_in;
    Vector position_in;
    double radius_in;
    double rho_in;


    //open file and define file pointer
    std::ifstream particle_input ("particle_input.dat");

    //go through each line in particle_input.dat and define each particle
    if (particle_input.is_open()) {
        for(int i=0;i&lt;input_data.num_particles();i++) {
            //read one line from particle_input.dat
            particle_input &gt;&gt; position_in;
            particle_input &gt;&gt; radius_in;
            particle_input &gt;&gt; rho_in;
            particle_input &gt;&gt; velocity_in;

            //set particle properties and position/velocity
            particles.getpart(i).setrho(rho_in);
            particles.getpart(i).setradius(radius_in);
            particles.getpart(i).move(position_in);
            particles.getpart(i).accelerate(velocity_in);
        }
    }
    //close file
    particle_input.close();
}
</code></pre>

<p>I've been looking all over for someone who had the same issue, but I was unable to find anything.
Thanks for the help.</p>
