0

My code is this:

Main.cpp

#include <iostream>

#include "Sally.hpp"

using namespace std;

int main() {

    Sally so;
}

//i only wanted to define an object. 

Sally.cpp

#include <iostream> 
#include "Sally.hpp"  
using namespace std;

Sally::Sally() // this part is the constructor
{
    cout << "Hi. This is the constructo." << endl;
}

Sally::~Sally() 
{
    cout<< "what's up" << endl; //deconstructor
}

Sally.hpp

#ifndef SALLY_H
#define SALLY_H

class Sally  //just defined a class
{
    private:

    public:
        Sally(); // just declared a constructor. remember constructor is just the same name as class 
        ~Sally(); // just declared a deconstructor
};
#endif

And I get the error message:

main Undefined symbols for architecture x86_64: "Sally::Sally()", referenced from: _main in main-247326.o "Sally::~Sally()", referenced from: _main in main-247326.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have no idea why it does this, but this always happens when I try to link class files to main.cpp. I haven't been programming for a while, but i'm not sure if there is something wrong with my terminal (like I need to install something) or I messed up somewhere.

Yusha
  • 1
  • How are you linking the object files together? – Eljay Jan 26 '22 at 02:33
  • 1
    Are you doing the actual build entirely from a terminal ? if so, put your build command for creating your program [**in your question**](https://stackoverflow.com/posts/70858054/edit). And regarding that specific sort of error, read this: [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). – WhozCraig Jan 26 '22 at 02:36
  • You are most likely not compiling all of your source files into your executable. If you are using VSCode remember that it by default only compiles the active file into your executable. It will ignore all other source files in the same folder. The documentation explains the change needed. I answered a similar problem today: [https://stackoverflow.com/questions/70856563/vscode-g-it-isnt-finding-cpp-definition-files/70856902#70856902](https://stackoverflow.com/questions/70856563/vscode-g-it-isnt-finding-cpp-definition-files/70856902#70856902) – drescherjm Jan 26 '22 at 03:11

0 Answers0