Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cmake的文件生成_C++_Cmake_Bison_Flex Lexer - Fatal编程技术网

C++ cmake的文件生成

C++ cmake的文件生成,c++,cmake,bison,flex-lexer,C++,Cmake,Bison,Flex Lexer,我有一个automake build system项目,那里有flex/bison文件。现在我不明白如何将它们包含到cmake构建系统中。我正在尝试手动执行此操作。以下是项目树: +ROOT |---CMakeLists.txt |---Sources/ | |---Flex | |---Main | |---CMakeLists.txt |---Includes/ 在Flex文件夹中有两个文件:player\u command\u parser.ypp;播放器\u命令\u tok

我有一个automake build system项目,那里有flex/bison文件。现在我不明白如何将它们包含到cmake构建系统中。我正在尝试手动执行此操作。以下是项目树:

+ROOT
|---CMakeLists.txt
|---Sources/
|   |---Flex
|   |---Main
|   |---CMakeLists.txt
|---Includes/
Flex
文件夹中有两个文件:
player\u command\u parser.ypp;播放器\u命令\u tok.lpp
。这些文件来自

我真的不知道如何在新的构建系统中使用它们,所以我决定手动生成所有文件:

flex --c++ player_command_tok.lpp 
此命令生成以以下代码开头的
lex.RCSSPCom.cc

#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
下一步是:
bison-dplayer\u command\u parser.ypp

我得到:
player\u command\u parser.tab.cpp;player\u command\u parser.tab.hpp

现在我正在尝试将所有生成的文件复制到相关文件夹:*.tab.hpp->Includes,并将cc&cpp文件添加到
Sources/CMakeLists.txt

set (FlexSources
    Server/Flex/lex.RCSSPCom.cc
    Server/Flex/player_command_parser.tab.cpp
)
以及编译输出:

[  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’

有什么问题吗?

您的编译错误似乎是由于某些头被包含了两次。您可能需要制作一个额外的文件,该文件只不过是一个include-guard:

玩家_命令_-tok_-guarded.hpp:

#ifndef PLAYER_COMMAND_TOK_GUARDED
#define PLAYER_COMMAND_TOK_GUARDED
#include "player_command_tok.hpp"
#endif
并使您的文件包含此新文件。至于将flex和bison集成到您的CMake系统中,请尝试以下方法:

# Find flex and bison.
find_program(FLEX flex DOC "Path to the flex lexical analyser generator.")
if(NOT ${FLEX})
  message(SEND_ERROR "Flex not found.")
endif
find_program(BISON bison DOC "Path to the bison parser generator.")
if(NOT ${BISON})
  message(SEND_ERROR "Bison not found.")
endif

# Custom commands to invoke flex and 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)

并像往常一样将文件添加到您的文件列表中。

要检查的蠢事:页眉保护。