Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22475

Flex and Bison GCC compile error, ld: library not found for -lfl

$
0
0

While compiling the flex and bison sources for a simple scanner I encounter the following error:

$ gcc -o lab5 lab5.tab.c lex.yy.c -lfl
ld: library not found for -lfl
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The lex source code:

%{

#include <stdio.h>
#include <string.h>
#include "lab5.tab.h"
void showError();
%}

integer (\+?[1-9][0-9]*)
id ([a-zA-Z_][a-zA-Z0-9_]*)

%%

{id} {sscanf(yytext, "%s", yylval.name); return ID;}
{integer} {yylval.number = atoi(yytext); return INT;}
";" return SEMICOLON;
. {showError(); return OTHER;}

%%

void showError() {
    printf("Other input");
}

The bison source code:

%{
    #include <stdio.h>
    int yylex();
    int yyerror(char *s);
%}

%token ID INT SEMICOLON OTHER

%type <name> ID
%type <number> INT

%union {
    char name[20];
    int number;
}

%%
prog:
    stmts
;
stmts:
        | stmt SEMICOLON stmts

stmt:
        ID {
                printf("Your entered an id - %s", $1);
        }
        | INT {
                printf("The integer value you entered is - %d", $1);
        }
        | OTHER
;
%%

int yyerror(char *s) {
    printf("Syntax error on line: %s\n", s);
    return 0;
}

int main() {
    yyparse();
    return 0;
}

Run the following commands to have all the source files:

flex -l lab5.l
bison -dv lab5.y

I am using macOS Mojave 10.14.6 with:

  • bison (GNU Bison) 2.3
  • flex 2.5.35 Apple(flex-31)
  • gcc 4.2.1

Viewing all articles
Browse latest Browse all 22475

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>