I have a project with automake build system and there are flex/bison files there. Now I can’t understand how to include them into cmake build system. I’m trying to do this manually. Here is the project tree:
+ROOT
|---CMakeLists.txt
|---Sources/
| |---Flex
| |---Main
| |---CMakeLists.txt
|---Includes/
In Flex folder there are 2 files: player_command_parser.ypp; player_command_tok.lpp. These files are from RoboCup soccer server.
I don’t really know how to use them with new build system so I decided to generate all files manually by hands:
flex --c++ player_command_tok.lpp
This command generates lex.RCSSPCom.cc which starts with the following code:
#line 3 "lex.RCSSPCom.cc"
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
/* The c++ scanner is a mess. The FlexLexer.h header file relies on the
* following macro. This is required in order to pass the c++-multiple-scanners
* test in the regression suite. We get reports that it breaks inheritance.
* We will address this in a future release of flex, or omit the C++ scanner
* altogether.
*/
#define yyFlexLexer RCSSPComFlexLexer
The next step is: bison -d player_command_parser.ypp.
I got: player_command_parser.tab.cpp; player_command_parser.tab.hpp
Now I’m trying to copy all generated files to related folders: *.tab.hpp -> Includes, and added cc&cpp files into Sources/CMakeLists.txt:
set (FlexSources
Server/Flex/lex.RCSSPCom.cc
Server/Flex/player_command_parser.tab.cpp
)
And the compile output:
[ 1%] Building CXX object Sources/Flex/lex.RCSSPCom.cc.o
In file included from /Includes/player_command_tok.h:31:0,
from player_command_tok.lpp:28:
/usr/include/FlexLexer.h:112:7: error: redefinition of ‘class RCSSPComFlexLexer’
/usr/include/FlexLexer.h:112:7: error: previous definition of ‘class RCSSPComFlexLexer’
What could be wrong?
Your compile error appears to be due to some header being included twice. You may need to make an extra file that is little more than an include guard:
player_command_tok_guarded.hpp:
And make your files
#includethis new file instead. As to integrating flex and bison into your CMake system, try something like this:And add the files to your file list as usual.