Gcc 编译过程中出错\u未定义引用

Gcc 编译过程中出错\u未定义引用,gcc,compilation,bison,Gcc,Compilation,Bison,我的文件mycop.l %{ #include <stdlib.h> #include <stdio.h> #include "y.tab.h" int yyerror(char *); %}

我的文件mycop.l

  %{                                                                                                    
 #include <stdlib.h>
        #include <stdio.h>
         #include "y.tab.h"
           int yyerror(char *);
        %}

 %%
         [a-z]       {
                  yylval = *yytext - 'a';
                return VAR;
            }
         [0-9]+      {
                yylval = atoi(yytext);
                return INT;
            }
         [-+()=/*\n] { return *yytext; } [ \t]       ;

         .           { yyerror("Input non valido"); }

         %% int yywrap(void){
         return 1; }
但我有一个错误:

       /tmp/ccaHRWZu.o: In function `yyparse':
       y.tab.c:(.text+0x24a): undefined reference to `yylex'
       collect2: ld returned 1 exit status
我安装的所有程序都在最新版本中更新。我无法理解问题出在哪里?我能做些什么来解决此错误。请帮助我修复它。谢谢大家
thk's all

您缺少链接器标志
-lfl
,该标志将解析器链接到定义了yylex的flex库。此外,还需要构建flex的输出。该c文件可能被称为:
mycop.lex.c

编译时使用:

gcc -o myComp y.tab.c myComp.lex.c -lfl
       /tmp/ccaHRWZu.o: In function `yyparse':
       y.tab.c:(.text+0x24a): undefined reference to `yylex'
       collect2: ld returned 1 exit status
gcc -o myComp y.tab.c myComp.lex.c -lfl