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

  • SEARCH
  • Home
  • 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 8929845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:45:38+00:00 2026-06-15T08:45:38+00:00

I am using a Makefile to compile a C++ project, and I receive an

  • 0

I am using a Makefile to compile a C++ project, and I receive an undefined reference error which I suspect is for a simple mistake.

The error itself is:

$ make
g++ -c main.cpp
g++ -o p5 main.o
main.o:main.cpp:(.text+0x241): undefined reference to `Instructions::processInput(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
Makefile:2: recipe for target `p5' failed
make: *** [p5] Error 1

Here are the parts of the project concerned with the error (for clarity’s sake):
My makefile:

p5: main.o Instructions.o
    g++ -o p5 main.o

main.o: main.cpp Instructions.h
    g++ -c main.cpp

Instructions.o: Instructions.h Instructions.cpp
    g++ -c Instructions.cpp

My main.cpp file:

#include <string>
#include "Instructions.h"
using namespace std;

int main() {
    Instructions inst;
    inst.processInput("some string par example"); //THIS LINE HERE GIVES ME ERRORS
    return 0;
}

My Instructions header file:

#ifndef INSTRUCTIONS_H
#define INSTRUCTIONS_H
#include <string>

class Instructions {
public:
    Instructions() {input = ""; command = 0; xCoord = 0.0; yCoord = 0.0;};
    void processInput(std::string in);
private:
    std::string input;
    int command;
    double xCoord;
    double yCoord;
};
#endif

And finally the .cpp file, very barebones at the moment:

#include "Instructions.h"
#include <string>
#include <iostream>
using namespace std;

void Instructions::processInput(string in) {
    cout << "Processing: " << input << endl;
}

I’ve been looking around for solutions but to no avail. Please excuse me then if it is indeed somewhere else! I also hope it helps all the beginners out there still coming to terms with C++!

  • 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-06-15T08:45:39+00:00Added an answer on June 15, 2026 at 8:45 am

    try this please Makefile :

     p5: Instructions.o main.o
         g++ Instructions.o main.o -o p5 
    
     Instructions.o: Instructions.cpp
         g++ -c Instructions.cpp -o Instructions.o 
    
     main.o: main.cpp Instructions.h
         g++ -c main.cpp Instructions.o -o main.o
    

    to compile p5, you need first to compile all its dependencies which is Instructions.o and main.o. Instructions.o is independent, so it can be compiled like this g++ -c Instructions.cpp. But main.o depend on the class Instructions so it depend on its .o It should be compiled like this g++ -c main.cpp Instructions.o.

    Same thing for p5, it needs all the *.o.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When compiling a project via a makefile using the Emacs compile command, when gdb
I'm trying to build/compile a old project using the original makefile. When I do
I'm trying to compile .cpp files as objective-c++ using makefile as few of my
I'm trying to compile some fortran files in Xcode, using a makefile made by
I'm new to C programming. I want to compile C program using Make file.
I'm writing a custom makefile project using QtCreator and I want to delete a
For few days I'm trying to compile one project written in C++ using Code::Blocks
I am working on a project for which we will be using ParseKit. Currently
When I tried to build a project in Linux, I got Error: undefined symbol
I'm currently trying to compile an existing project which is a mix of cpp

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.