Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6329409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:39:31+00:00 2026-05-24T17:39:31+00:00

I am trying to link several object files and I am getting 3 undefined

  • 0

I am trying to link several object files and I am getting 3 undefined reference to a function errors.

inputtest.cpp

//test of input methods

#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <vector>


#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 <<endl<< particles.getpart(1).rho()<<endl<<particles.getpart(1).radius()<<endl;

    return 0;
}

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

undefined reference to ‘berger_DEM::read_particle_input(berger_DEM::Particle_vector&, berger_DEM::User_input&)

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.

prototype:

namespace berger_DEM
{   
    void read_particle_input(Particle_vector&,User_input&);
}

implementation:
//method to read in particle_input.dat

void read_particle_input(Particle_vector & particles, User_input & 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<input_data.num_particles();i++) {
            //read one line from particle_input.dat
            particle_input >> position_in;
            particle_input >> radius_in;
            particle_input >> rho_in;
            particle_input >> 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();
}

I’ve been looking all over for someone who had the same issue, but I was unable to find anything.
Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:39:33+00:00Added an answer on May 24, 2026 at 5:39 pm

    Your implementation is missing the class scope.

    change

    void read_particle_input(Particle_vector & particles, User_input & input_data) 
    {
        //define local variables
    

    to

    void berger_DEM::read_particle_input(Particle_vector & particles, User_input & input_data) 
    {
        //define local variables
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm receiving the infamous undefined reference error when trying to compile & link several
I'm trying to get a link text using regex. there are possibly several links
I have several links I'm trying to create to either perform custom controller methods
I am trying to link some Boost .hpp files with Monodevelop, but I don't
I'm getting famous unsatisfied link error when I'm trying to launch my C++ based
When trying to link some well established tools to my company's active directory, I
I am trying to link two fields of a given table to the same
I am trying to link to a file that has the '#' character in
I'm trying to link an RPATH containing the special string $ORIGIN into an executable
I'm trying to link Mochiweb with my ejabberd mnesia db and am unable to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.