Reputation: 575
I am trying to execute FLEX
program from the Github on windows and I have installed Flex
and MingW
Compiler.
I have added below paths to Environmental variables
After that, I trying to execute make
command and I got the below output
g++ -g -Wall -ansi -pedantic -std=gnu++0x bison.o lex.o main.o -o mini_lang -lfl
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lfl
collect2.exe: error: ld returned 1 exit status
make: *** [mini_lang] Error 1
Below is Makefile
OBJ = bison.o lex.o main.o
CC = g++
CFLAGS = -g -Wall -ansi -pedantic -std=gnu++0x
mini_lang:$(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o mini_lang -lfl
lex.o: lex.c
$(CC) $(CFLAGS) -c lex.c -o lex.o
lex.c: lex_final.l
flex lex_final.l
cp lex.yy.c lex.c
bison.o: bison.c
$(CC) $(CFLAGS) -c bison.c -o bison.o
bison.c: grammar.y
bison -d -v grammar.y
cp grammar.tab.c bison.c
cmp -s grammar.tab.h tok.h || cp grammar.tab.h tok.h
main.o: main.cc
$(CC) $(CFLAGS) -c main.cc -o main.o
lex.o yac.o main.o: headers.h
lex.o main.o: tok.h
clean:
rm -f *.o *~ lex.c lex.yy.c bison.c tok.h grammar.tab.c grammar.tab.h grammar.output mini_lang
Please, can anyone help me to fix this error?
Upvotes: 1
Views: 14453
Reputation: 19
If you use the MinGW compiler, open InstallationManager and install this package:
mingw32-pthreads-w32
Upvotes: 1
Reputation: 241671
My advice is to find a different tutorial.
Either the flex distribution you installed does not include libfl
or you did not add the path to libfl
to the correct environment variable. You might try adding the path explicitly to the minilang rule, using a -L
option before -lfl
: ... -L /path/to/directory-containinglibfl -lfl
.
However, there is absolutely no need for -lfl
, so the better solution is to just remove it from the minilang
action, and add
%option noyywrap
to your flex input file. (That will prevent it from producing a scanner which calls yywrap
, so you will not require the yywrap
which is in libfl
.)
Upvotes: 1
Reputation: 18541
I'm using MingW+MSYS2, and for me the Flex library is located at c:\msys32\usr\lib\libfl.a
.
Try searching for libfl.a
in your MinGW folder tree, and use the -L
compiler/linker flag, followed by the folder path where the library is located, to instruct the compiler/linker to look for libfl.a
in that location.
For example:
g++ -g -Wall -ansi -pedantic -std=gnu++0x bison.o lex.o main.o -o mini_lang -lfl -Lc:\msys32\usr\lib
Upvotes: 0