Assembled from comments (because it was easier than finding a dupe):
-
In modern C (that is, C from this century), all functions need a return type and the only two legal prototypes for
main
are:int main(void) int main(int argc, char* argv[])
An obsolescent way to write the first is
int main()
. -
On Max OS, the flex distro doesn’t include
libfl.a
. It comes withlibl.a
. So use-ll
instead of-lfl
. But much better is to avoid the problem by telling flex not to requireyywrap
by putting the following declaration in your prologue:%option noyywrap
Even better is to use the following:
%option noinput nounput noyywrap nodefault
noinput
andnounput
will avoid “unused function” warnings when you compile with warnings enabled (which you should always do).nodefault
tells flex to not insert a default action, and to produce a warning if one would be necessary. The default action is to echo the unmatched character on stdout, which is usually undesirable and often confusing.
7
solved C error with Flex: type specifier missing?