[GoLUG] [parse] Flex compile library inclusion and double declaration of main error

Steve Litt slitt at troubleshooters.com
Fri Nov 24 22:28:41 EST 2023


Hi all,

Hi all,

sometimes you want to compile in the Flex library, using -lfl. A very
obscure fact is that if you don't put that -lfl after the files that
get compiled, you get a compiler error stating that you have a multiple
declaration of main(), because main() is declared in the Flex library
*and* in your Flex program (presumably). The following compiles
perfectly:

gcc -Wall lex.yy.c -lfl

But the following errors out with multiple definitions of main():

gcc -Wall -lfl lex.yy.c

Very few people know this, so when somebody reports multiple
definitions of main() with Flex and the Flex library linked in,
respondents typically send the guy asking the question on a wild goose
chase. Please remember this.

SteveT

Steve Litt 

Autumn 2023 featured book: Rapid Learning for the 21st Century
http://www.troubleshooters.com/rl21



More information about the GoLUG mailing list