I wrote an extremely simple program with 3 files:
hash.cpp
#include <iostream>
#include <string>
#include "hash.h"
using namespace std;
void hashclass::test(){
cout << "Inside the hashclass function def" << endl;
cout << "Hello!" << endl; }
hash.h
#include <iostream>
#include <string>
using namespace std;
#ifndef HASH_H
#define HASH_H
class hashclass{
public:
void test();
};
#endif
main.cpp
#include <iostream>
#include <string>
#include "hash.h"
#include <cstdlib>
using namespace std;
int main(int argc, char **argv){
hashclass hashObj;
hashObj.test();
return 0;}
When compiling using g++, I am getting the below error:
Undefined symbols for architecture x86_64:
"hashclass::test()", referenced from: _main in main-9f5786.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 tried a lot to figure out what went wrong, I don't see any issue with above code.