c++ - File generating for cmake -
i have project automake build system , there flex/bison files there. can't understand how include them cmake build system. i'm trying manually. here project tree:
+root |---cmakelists.txt |---sources/ | |---flex | |---main | |---cmakelists.txt |---includes/
in flex
folder there 2 files: player_command_parser.ypp; player_command_tok.lpp
. these files robocup soccer server.
i don't know how use them new build system decided generate files manually hands:
flex --c++ player_command_tok.lpp
this command generates lex.rcsspcom.cc
starts following code:
#line 3 "lex.rcsspcom.cc" #define yy_int_aligned short int /* lexical scanner generated 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 /* c++ scanner mess. flexlexer.h header file relies on * following macro. required in order pass c++-multiple-scanners * test in regression suite. reports breaks inheritance. * address in future release of flex, or omit 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 copy generated files related folders: *.tab.hpp -> includes, , added cc&cpp files sources/cmakelists.txt
:
set (flexsources server/flex/lex.rcsspcom.cc server/flex/player_command_parser.tab.cpp )
and compile output:
[ 1%] building cxx object sources/flex/lex.rcsspcom.cc.o in file included /includes/player_command_tok.h:31:0, 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 wrong?
your compile error appears due header being included twice. may need make file little more include guard:
player_command_tok_guarded.hpp:
#ifndef player_command_tok_guarded #define player_command_tok_guarded #include "player_command_tok.hpp" #endif
and make files #include
new file instead. integrating flex , bison cmake system, try this:
# find flex , bison. find_program(flex flex doc "path flex lexical analyser generator.") if(not ${flex}) message(send_error "flex not found.") endif find_program(bison bison doc "path bison parser generator.") if(not ${bison}) message(send_error "bison not found.") endif # custom commands invoke flex , bison. add_custom_command(output lex.rcsspcom.cc command ${flex} --c++ player_command_tok.lpp main_dependency player_command_tok.lpp comment "generating lexer" verbatim) add_custom_command(output player_command_parser.tab.cpp player_command_parser.tab.hpp command ${bison} -d player_command_parser.ypp main_dependency player_command_parser.ypp comment "generating parser" verbatim)
and add files file list usual.
Comments
Post a Comment