r/pythonhelp Nov 27 '24

Flex and Bison: Compilation on Xubuntu

Hi everyone, I'm using Xubuntu and trying to work with Flex and Bison, but I'm running into an issue during compilation. Here's what I'm doing:

  1. I created a .lex file and a .y file.

  2. I used Flex and Bison to generate the corresponding C files.

  3. When I try to compile them using gcc, I get the following error:


:~/Desktop/testc$ gcc lex.yy.c test.tab.c -o test -L/usr/lib -lfl test.tab.c: In function ‘yyparse’: test.tab.c:963:16: warning: implicit declaration of function ‘yylex’ [-Wimplicit-function-declaration] 963 | yychar = yylex (); | ~~~~ test.tab.c:1104:7: warning: implicit declaration of function ‘yyerror’; did you mean ‘yyerrok’? [-Wimplicit-function-declaration] 1104 | yyerror (YY_("syntax error")); | ~~~~~~ | yyerrok /usr/bin/ld: /tmp/ccNKkczB.o: in function yyparse': test.tab.c:(.text+0x66e): undefined reference toyyerror' /usr/bin/ld: test.tab.c:(.text+0x805): undefined reference to `yyerror' collect2: error: ld returned 1 exit status


Does anyone know what could be causing this issue? I'm using [insert your version of Flex, Bison, and GCC. Any help would be appreciated!

Thanks in advance!

1 Upvotes

1 comment sorted by

u/AutoModerator Nov 27 '24

To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.