I'm new to c++, this class will be used with a flex scanner. I'm keeping it simple here just to get it to compile but I'm getting the following message (none of other threads about this message seem to apply to my situation):
Undefined symbols for architecture x86_64: "Listing::lexicalError", referenced from: Listing::Listing() in listing.o Listing::displayErrorCount() in listing.o Listing::increaseLexicalError() in listing.o ld: symbol(s) not found for architecture x86_64
Listing.h
using namespace std;
class Listing
{
public:
enum ErrorType {LEXICAL, SYNTAX, SEMANTIC};
Listing();
void appendError(ErrorType error, char yytext[]);
void displayErrorCount();
void increaseLexicalError();
private:
static int lexicalError;
};
Listing.cpp
#include <iostream>
#include <sstream>
using namespace std;
#include "Listing.h"
Listing::Listing()
{
lexicalError = 0;
}
void Listing::appendError(ErrorType error, char yytext[])
{
switch (error) {
case LEXICAL:
cout << "Lexical Error, Invalid Character " << yytext << endl;
break;
case SEMANTIC:
cout << "Semantic Error, ";
case SYNTAX:
cout << "Syntax Error, ";
default:
break;
}
}
void Listing::displayErrorCount()
{
cout << "Lexical Errors " << lexicalError << " ";
}
void Listing::increaseLexicalError()
{
lexicalError++;
}
Thanks for any help compiling. I'm sure the c++ code isn't pretty but I'm learning ...
Here's the Makefile:
compile: scanner.o listing.o
g++ -o compile scanner.o listing.o
scanner.o: scanner.c listing.h tokens.h
g++ -c scanner.c
scanner.c: scanner.l
flex scanner.l
mv lex.yy.c scanner.c
listing.o: listing.cpp listing.h
g++ -c listing.cpp