TL;DR: remove %option c++
.
The -lfl
is required.
Are you sure? libfl provides only two functions: yywrap()
, which you do not need because of
%option noyywrap
, and main()
, which you do not need if you provide your own main()
. The main()
in libfl just calls yylex()
over and over until the latter signals end-of-input, which is surely where the depency on yylex()
is coming from in your case.
If you have some external requirement to rely on libfl for your program's main
, then you have shot yourself in the foot by specifying
%option c++
. That option is more about the API the generated scanner will provide than about the language that will be used to compile it. You do need to compile as C++ if you use it, but you can still compile as C++ if you don't. You should omit that option to have yylex()
as the scanner entry point.
Declaring C linkage for yylex()
is what you do if you plan to omit %option c++
, compile with a C++ compiler, and link with other code (such as libfl) that expects the C interface for yylex()
. But it is rare for that to be an advantageous combination, because the kinds of actions a typical scanner wants to perform don't gain much from C++ relative to C. Thus, if you want the C interface to yylex()
then it is usually cleaner to just write the actions in C and compile the scanner with a C compiler. And of course, you can still call that from C++ if you like.