For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2006 > compilation error of Lex.yy.c









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author compilation error of Lex.yy.c
sam_cit@yahoo.co.in

2006-03-27, 4:00 am

Hi,
I just have the simple lex program
%%
. ECHO;
%%
int main()
{
yylex();


}


i did this, lex sample.l, which resulted in lex.yy.c then i tried to
complie the produced c file, on which i get the following error,

/tmp/ccYMo5KN.o: In function `yylex':
/tmp/ccYMo5KN.o(.text+0x353): undefined reference to `yywrap'
/tmp/ccYMo5KN.o: In function `input':
/tmp/ccYMo5KN.o(.text+0xb1a): undefined reference to `yywrap'
collect2: ld returned 1 exit status


Only way i have worked out is to have my own yywrap() function which
returns 1 always, but having said iam not able to understand the cause
of the problem, a simple lex program should work, like the following
%%
.. ECHO;
%%


but why isn't?

Nils O. Selåsdal

2006-03-27, 8:00 am

sam_cit@yahoo.co.in wrote:
> Hi,
> I just have the simple lex program
> %%
> . ECHO;
> %%
> int main()
> {
> yylex();
>
>
> }
>
>
> i did this, lex sample.l, which resulted in lex.yy.c then i tried to
> complie the produced c file, on which i get the following error,
>
> /tmp/ccYMo5KN.o: In function `yylex':
> /tmp/ccYMo5KN.o(.text+0x353): undefined reference to `yywrap'
> /tmp/ccYMo5KN.o: In function `input':
> /tmp/ccYMo5KN.o(.text+0xb1a): undefined reference to `yywrap'
> collect2: ld returned 1 exit status

Link to the libfl library. That is, something akin to:
cc -Wall -o sample lex.yy.c -lfl
sam_cit@yahoo.co.in

2006-03-27, 8:00 am

well, i tried this and i did this,

cc lex.yy.c -lfl

the problem is solved and its working fine, but what does the above
command do and how is the problem solved?
Does that library have the definition for yywrap(), the default
function()...

Nils O. Selåsdal

2006-03-27, 8:00 am

sam_cit@yahoo.co.in wrote:
> well, i tried this and i did this,
>
> cc lex.yy.c -lfl
>
> the problem is solved and its working fine, but what does the above
> command do and how is the problem solved?
> Does that library have the definition for yywrap(), the default
> function()...

My flex manpage says
"If you do not supply your own version of yywrap(), then you must
either use %option noyywrap (in which case the scanner behaves as though
yywrap() returned 1), or you must link with -lfl to obtain the default
version of the routine, which always returns 1."


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com