I have a pretty standard .l file for flex
to to process.
scanner.l
%{
#include "sFile.h"
%}
%%
"BEGIN" return BG;
"END" return END;
"And so on...."
%%
int yywrap()
{
return 1
}
So I hit this with a flex -+ scanner.l
and like magic a lex.yy.cc
file shows up.
I turn to my trusty c++ compiler and g++ lex.yy.cc
just to give it a go and I get
lex.yy.cc: In member function 'virtual int yyFlexLexer::yylex()':
lex.yy.cc:868: error: 'yywrap' was not declared in this scope
lex.yy.cc: In member function 'int yyFlexLexer::yyinput()':
lex.yy.cc:1271: error: 'yywrap' was not declared in this scope
I've also tried modifying the scanner.l
to use %option c++
and a few other things but I can't for the life of me figure out how to get this thing to compile.
The end result is is using this with an external .cpp file to do some other work for the assignment.
edit: Versions g++ 4.1.1 flex 2.5.33
edit for dupe clarification: I'm not using bison, we have to write the parse step on our own without a generator(Like bison). Each of the other related questions have this problem entangled with another tool. I'm terribly weak in this area as a student so I am having trouble translating what bison needs and what my cpp file needs.
However %option noyywrap
did clarify/fix that problem but really just opened up a whole different can of worms.
Perhaps it would be best if I just restated the intent.
I need to run a flex scanner on an input file. I need to parse that output in my own .cpp file. My c is super weak and there isn't enough time in the project for our group to do it in c.
It's important that I have access to
extern int yylex();
extern int yylineno;
extern char* yytext;
extern FILE* yyin;
In my .cpp parser. All of which seem to error when compiled. -lfl
is giving me an error
g++ lex.yy.cc program.cpp -lfl
ld: fatal: library -lfl: not found
ld: fatal: File processing errors. No output written to a.out
ninja edit: I found the flex libs
$ g++ lex.yy.cc -L /usr/local/lib -lfl
using
this question but I am still getting the same error. error: 'yywrap' was not declared in this scope
I've also tried to compile lex.yy.cc
on its own with the same error.
Trying to get to a simpler state I also removed the yywrap
definintion from scanner.l
and replaced with
int main()
{
yylex();
}
Where I received the following error.
Undefined first referenced
symbol in file
yylex() /var/tmp//ccjy7kng.o
So then I took all of that noise out and simply put a int main(){return 1;}
and it compiled. But when I tried to compile with my .cpp parser
ld: fatal: symbol `main' is multiply-defined: