I am learning C++. I have tried linking separate files in an attempt to have a class in a seperate file.
When I build and run the program I get this error message:
Undefined symbols for architecture x86_64: "Sally::printCrap()", referenced from: _main in Main-8bfa94.o "Sally::Sally()", referenced from: _main in Main-8bfa94.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) [Finished in 0.3s with exit code 1]
Here is my code:
Main.cpp
#include <iostream>
#include <string>
#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();
};
#endif
Sally.cpp
#include "Sally.h"
#include <iostream>
using namespace std;
Sally::Sally()
{
}
void Sally::printCrap(){
cout << "Crap \n";
};
Any help would be greatly appreciated!
Sally.cpp
(and therefore you don't link it). Tryg++ main.cpp a.cpp
– vsoftco