I’m getting this error creating a new object with KarateMatch new_match; when compiling my Driver.cpp file with g++ Driver.cpp KarateMatch.cpp -o output:
Undefined symbols for architecture x86_64:
"KarateMatch::KarateMatch()", referenced from:
_main in cc5G5Ak8.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
KarateMatch new_match;
I can’t figure out what I’ve done wrong, since I am using #include <KarateMatch.h> on both Driver.cpp and KarateMatch.cpp:
Edit:
I’ve tried the code as exactly shown on my system (OS X 10.8.1), and this isn’t compiling with the same error.
KarateMatch.h
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class KarateMatch{
public:
KarateMatch();
};
KarateMatch.cpp
#include "KarateMatch.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
KarateMatch::KarateMatch(){
cout << "HI";
}
its running fine on my system g++-4.3..
i think its not the problem with KarateMatch.h and KarateMatch.cpp files.
try compiling only Driver.cpp first without including KarateMatch.h file and without creating its object .