2012-04-11 122 views
0

我正在编译几个lex和yacc程序。在大学我们使用Fedora Core 4.我在家中的虚拟机上使用相同的操作系统,但我无法编译程序。以下是lex和yacc代码无法编译Lex和Yacc程序

LEX代码

%{ 
#include "y.tab.h" 
%} 
%% 
[ \t]+ {;} 
\n {return;} 
[a-zA-Z][a-zA-Z0-9]* {return ID;} 
[0-9]+ {return NUMBER;} 
. {return yytext[0];} 
%% 

YACC代码

%{ 
#include<stdio.h> 
%} 
%token NUMBER ID 
%left '+' '-' 
%left '*' '/' 
%% 
input:e'+'e 
|e'-'e 
|e'*'e 
|e'/'e 
|'('e')' 
; 
e:NUMBER 
|ID 
; 
%% 
int main() 
{ 
printf("\n\nEnter an expression"); 
yyparse(); 
printf("\n\nValid Expression\n\n"); 
} 
void yyerror() 
{ 
printf("\n\nInvalid Expression\n\n"); 
exit(0); 
} 

While executing the above code, I get the following linker error 

$ lex program_name.l      //executes without error 
$ yacc -d program_name.y     //executes without error 
$ cc lex.yy.c y.tab.c -ll -ly 
/usr/bin/ld: cannot find -ly 
collect2: ld returned 1 exit status 

请帮我解决这个错误。在此先感谢

回答

0

这与您的YACC LIB做... 你将需要包括与-L"/some/path/to/lib-directory"选项

或可能需要安装相应的lib目录...

1

This conversion概述了你的问题:你需要安装liby并且编译器需要设置正确的库路径(例如-L/usr/lib)

-ly选项告诉链接器与liby库链接,但根据到错误,它找不到该库

1

有没有这样的事情-ly。 Lex和flex生成的扫描程序使用运行时支持库。 yacc生成的分析器不会。只需拿出-ly并再试一次。