Reputation: 38
Wrote the following code in flex and c file has generated but compiler shows "undefined reference to 'yywrap' " error.
%{
int nchar;
int nline;
%}
%%
[\n] {nline++;}
. {nchar++;}
%%
void main(void){
yylex();
printf("%d%d,nchar,nline");
}
Questions like this have been asked and all the answers were based on ignoring yywrap function like adding #define yywrap() 1 Which in this case the program runs but doesn't work but I want it to work.
Upvotes: 1
Views: 2407
Reputation: 575
You can define it yourself like this:
int yywrap() {
// open next reference or source file and start scanning
if((yyin = compiler->getNextFile()) != NULL) {
line = 0; // reset line counter for next source file
return 0;
}
return 1;
}
Or decide not to use it:
%option noyywrap
Or install it; which is like this for a redhat-based os:
yum -y install flex-devel
./configure && make
Upvotes: 1