Flukiluke Flukiluke - 1 month ago 7
C Question

flex: undefined reference to `yywrap' only when compiling/linking separately

I've been learning to use Flex (the lexical analyser) and I've been compiling with the following command:

gcc -lfl -o test lex.yy.c


and all is well. However, I want to link it with other files, so I compile and link it separately with

gcc -c lex.yy.c


followed by

gcc -lfl -o test lex.yy.o


but gcc tells me that there is an undefined reference to
yywrap()
. So, what's going on here?

I'm using Flex 2.5.35, gcc 4.7.2 and ld 2.22

Raj Raj
Answer

add -lfl at the end instead of beginning.