Monday, 9 September 2013

Undefined reference to file

Undefined reference to file

I'm trying to link/reference separate files together for compilation. I've
never done this before, so I'm lost with this error. It seems like I've
referenced what I need.
I've got three files, main.cpp, parser.cpp and header.h Main calls parser
to parse text (although I haven't been able to test if it actually works
yet :l )
main.cpp -
#include "header.h"
using namespace std; // I know this isn't recommended, I'm changing this
later.
int main(){
string input, arg1, arg2;
vector<string> parsedIn;
cout << "<";
while(getline(cin, input)){
parsedIn = parser(input);
//more code, this is the only call to parser and compile error
//stops here
parser.cpp -
#include "header.h"
std::vector<std::string> parse(std::string &input){
int i=0;
//int begin=1;
int count=0;
std::vector<std::string> parsedIn;
while(i<input.length()){
char temp = input.at(i);
if(temp != ' '){
parsedIn[count] += temp;
count++;
}
i++;
}
if(count < 3)
parsedIn[0] = "Error"; // Set first value to "Error" to report an
input issue
return parsedIn;
}
header.h
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
std::vector<std::string> parser(std::string &input);
I know I should be using guards as well, but my TA wasn't exactly clear on
how I set those up...baby steps though. This is my first time with C++ so
I'd like to figure out why this isn't being referenced.
The error is undefined reference to parser, of course.

No comments:

Post a Comment