I am unable to compile my code which I wrote on Xcode. The code compiles fine in Xcode but when I try to do it in Terminal, it gives the following error:
Undefined symbols for architecture x86_64:
"Parser::BeginParsing(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in a2-9afc30.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Now I know there are tons of threads already on StackOverflow on this matter but I seriously can't get to fix my error.
I have a file a2.cpp where I have a main function and I am creating a Parser P object in it and then call a P's function.
Here is the code for my a2 file:
#include "Parser.h"
int main(int argc, char** argv) {
Parser P;
while (!std::cin.eof()) {
// read a line of input until EOL and store in a string
std::string line;
std::getline(std::cin, line);
P.BeginParsing(line);
}
}
This is my Parser.h file:
#ifndef Parser_h
#define Parser_h
#include "Database.h"
#include "Graph.h"
class Parser {
public:
int totalVertices = 0;
std::vector<std::vector<std::string> > final_edges;
std::vector<int> pathToFind;
Database db;
Graph graph;
void createGraph();
void ParseInputVertices(std::string str);
void ParseVertices(std::string str);
void ParseEdges(std::string str);
void BeginParsing(std::string str);
};
#endif /* Parser_h */
And this is the Parser.cpp file:
#include "Parser.h"
void Parser::BeginParsing(std::string str) {
std::regex reV ("V\\s([0-9]+)");
std::regex reE ("E\\s");
std::regex reS ("s\\s");
std::smatch matches;
std::smatch matches1;
std::smatch matches2;
if (std::regex_search(str,matches,reV)) {
ParseVertices(str);
}else if (std::regex_search(str,matches1,reE)) {
ParseEdges(str);
}else if (std::regex_search(str,matches1,reS)) {
ParseInputVertices(str);
}
}
all other methods have also been defined in Parser.cpp file. This is , however, the function called from a2.cpp main function.
Any idea what I can do to fix this. Help will be appreciated. Thanks!