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 9274713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:25:01+00:00 2026-06-18T16:25:01+00:00

I think I’m getting close, but I’m having this error I’ve been banging my

  • 0

I think I’m getting close, but I’m having this error I’ve been banging my head against the wall on for hours. I’m missing something stupid, and I’ve gone character by character but I can’t find it.

The compiler is giving me

main.cpp:16: undefined reference to `translator::translator(std::istream&)'
collect2: error: ld returned 1 exit status

when I try to compile my program. The command I’m using to compile is:

clear && g++ -g -Wall main.cpp -o Pear

The three sections of use are as follows:

main.cpp

int main(int argc, char* argv[])
{

std::ifstream myFile;

myFile.open(argv[1]);

translator example(myFile); 

myFile.close(); 

return 0; 
}

translator.cpp

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

#include "translator.h"


translator::translator(std::istream& in)
{   
table1(in);
table2(in);
}

translator.h

#ifndef TRANSLATOR
#define TRANSLATOR

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

#include "translationTable.h"


class translator
{
private:

translationTable<std::string, int> table1;

translationTable<int, std::string> table2;

translator(); 

public:

translator(std::istream& in); 

};



#endif

Any ideas? I’ve tried so much, and I’ve looked up similar problems, but they all have different sources. Thanks in advance!

  • 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-18T16:25:02+00:00Added an answer on June 18, 2026 at 4:25 pm

    The command line for g++ needs to include both source files, like this:

    g++ -g -Wall main.cpp translator.cpp -o Pear
    

    Otherwise, the compiler has no idea from where to get the implementation of the translator::translator(std::istream&) member function.

    *EDIT: * (from the comment)

    I thought that basically the use of header files was so that it would know where to get each implementation of the file?

    This part is grossly oversimplified, but it should help you get the picture. Recall that the process of producing an executable from C++ sources consists of two major steps – compilation and linking. The g++ program performs them both (it can do just one if you specify -c flags, or pass only .o files).

    The compiler and the linker stages of g++ do not “talk” to each other directly. The compiler produces the inputs for the linker, and that’s where the communication ends.

    Header files are for the compiler. Specifically, they are for the first stage of compilation – the preprocessing. Once the preprocessor has finished, there is no knowledge of where the definitions came from. Even the compiler does not know it, let alone the linker. That is why you need to “help” the linker by supplying all the relevant sources to g++.

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

Sidebar

Related Questions

I think I read all the Infragistics and StackOverflow posts about this error, but
I think its a 5am brain drain, but I'm having trouble with understanding this.
I think this is pretty straightforward but I've been trying for days without a
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
i think this should be very easy , but i really don't know how
I think I've seen this answer, but I can't remember where for certain. I'm
I think it's strange that I can't find anything on this, but that's the
I think i am getting a little head of myself with the below, what
Think about doing this: import matplotlib.pyplot as plt plt.plot(x_A,y_A,'g--') plt.plot(x_B,y_B,'r-o') plt.show() How would you

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.