0

I try to compile this c++ program but i get this error:

"main.cpp:17: undefined reference to `Burrito::Burrito()' collect2: error: ld returned 1 exit status The terminal process terminated with exit code: 1"

What it should do, is printing: "Goodmorning". I really don't know what i am doing wrong but hope you guy can help me.

The main.cpp:

#include <iostream>
#include "Burrito.h"

using namespace std;


int main()
{
    Burrito bo;
    return 0;
}

The Burrito.h:

#ifndef BURRITO_H
#define BURRITO_H

class Burrito
{
    public:
        Burrito();
};

#endif

And the Burrito.cpp:

#include <iostream>
#include "Burrito.h"


using namespace std;

Burrito::Burrito()
{
    cout << "Goodmorning" << endl;

}
K.V.
  • 51
  • 1
  • 6
  • How are you compiling your program? What are your includes? – NotAProgrammer Apr 10 '20 at 13:03
  • 1
    You probably did not link the two object files together. How are you calling the compiler? – chi Apr 10 '20 at 13:03
  • 1
    `c17 main.cpp Buritto.cpp && ./a.out` worked for me. (`c17` is my modified clang++ toolchain driver, with targets C++17.) – Eljay Apr 10 '20 at 13:05
  • What do you mean by includes? I compile the code in vs code in ubuntu. I installed g++ (but i'm not sure) – K.V. Apr 10 '20 at 13:06
  • @chi where i can find the name of the compiler? i am a beginner – K.V. Apr 10 '20 at 13:08
  • Well, i think there is a something wrong with my compiler but i don't know what exactly – K.V. Apr 10 '20 at 13:13
  • See: https://stackoverflow.com/questions/51720769/how-to-use-visual-studio-code-to-compile-multi-cpp-file – flowit Apr 10 '20 at 13:25
  • Your [mcve] is missing the parts showing the command line that you use to compile the `.cpp` files and link the `.o` files. – Eljay Apr 10 '20 at 13:33
  • In the vs code options you should find how the underlying compiler is called. In ubuntu, probably something like `g++ many options main.cpp`. You must convince your vs code to link the results on both cpp files together. I'm not familiar with that tool, so I can't provide a better suggestion. – chi Apr 10 '20 at 13:40

0 Answers0