How to Use Flex with Multiple Source Files ========================================== 1) Write a Flex specification file, and use an extension of ".l" (dot ell). I will assume the file is named "WordCount.l". 2) Use Flex to generate a lexer. Flex will generate C code, but it is also valid C++ code so we will use an extension of ".cc" for the generated code. flex --nounput -o WordCountLexer.cc WordCount.l 3) Compile the generated lexer. g++ -Wall -c WordCountLexer.cc This MAY produce warnings about comparisons between signed and unsigned numbers. The warnings will not result in problems and can be ignored. 3) Write a driver file that invokes the generated lexer/scanner function "yylex", defined in "WordCountLexer.cc". I will assume the driver file is "WordCountDriver.cc". 4) Compile the driver file. g++ -Wall -c WordCountDriver.cc 5) Link the two generated object files together to produce an executable. g++ WordCountDriver.o WordCountLexer.o -o WordCountDriver -lfl Don't forget to link with the Flex library with "-lfl". 6) You will likely have errors :-) If you modify the Flex file, you need to re-run flex and recompile the generated lexer. You do NOT have to recompile the driver unless you modified it as well. Repeat the link step to generate an updated executable. 7) The above steps can be used with more than two source files. Just compile all source files and be sure to include all of them in the link command in step 5.