Having trouble with header and class file


#1

I have recently started learning c++ and until now I haven’t had too much trouble. However always when I try to use a .h and .cpp file I get an error. I have checked several times if my code has any syntaxe errors but can’t find any. As I am very new to programming I am not sure what I should change based on the error message I get.
I would be very happy if someone could help.

main file

#include
#include"Sally.h"

using namespace std;

int main(){

Sally sallyObject;
Sally *sallyPointer = &sallyObject;

sallyObject.printCrap();
sallyPointer->printCrap();

}

Sally.h

#ifndef SALLY_H
#define SALLY_H

class Sally
{

public:
Sally();
void printCrap();
protected:
private:

};

#endif

Sally.cpp

#include<Sally.h>>
#include

using namespace std;

Sally::Sally()
{
}

void Sally::printCrap(){
cout<<“did someone say steak?”<<endl;
}

error I get

Undefined symbols for architecture x86_64:
“Sally::printCrap()”, referenced from:
_main in arrow member selection operator-36056e.o
"Sally::Sally()", referenced from:
_main in arrow member selection operator-36056e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


#2

Atom does not have any ability to compile code, so you must be using an external package to do so. Please share which package that is.


#3

I am using gpp-compiler and have downloaded x-code as I have a mac.


#4

Have you been able to compile your code in Xcode? Do you have enough familiarity with the Terminal to attempt to compile on the command line, or would you require me to walk you through it?

I don’t use C++, so my knowledge of it is all peripheral and what I learned in school. I also don’t use a Mac, so I can’t test to see if I can replicate the issue. What I can do is help you figure out how to verify that the failure is happening on Atom’s side of the pipeline. If we find out that Xcode has the same issue, then you will need to seek more experienced help. If Xcode and the command line both work correctly, I might be able to help you figure out why it’s not working when Atom tries to do the same thing.


#5

I am now trying to compile my code in x code have only to look how I do that in x code. Will say if that works. I am not very familiar with the Terminal so I will need your help to do that. Thank you for your help I really appreciate it.


#6

Code in x code worked fine