2011-03-04 57 views
1

我試圖在同一個可執行文件中鏈接各種Flex ++詞庫。但是,由於符號重新定義,導致編譯錯誤。我試着設置不同的前綴,但它是沒有用的:這是我的選擇:Flex ++的多個詞法分析器

Lexer1:

%option c++ 
%option noyywrap 
%option yyclass="SendmailScanner" 
%option prefix="zz" 

Lexer2:

%option c++ 
%option noyywrap 
%option yyclass="SSHDFailureScanner" 
%option prefix="xx" 

根據手冊,我應該只取消設置變量yyFlexLexer並將其更改爲zzFlexLexer(在使用該詞法分析器的源文件中)或xxFlexerLexer。不幸的是,我得到了以下錯誤:

/usr/include/FlexLexer.h:103: error: redefinition of ‘class zzFlexLexer’ 
/usr/include/FlexLexer.h:103: error: previous definition of ‘class zzFlexLexer’ 

的時候我只有一個詞法此錯誤也出現連...我不知道該怎麼辦。

謝謝你在前進,

回答

1

雖然我沒有徹底測試,當我 用簡單的文件測試未發生重定義錯誤。 我的flex的版本是2.5.35。 爲了您的信息,我的測試文件被配置如下所示:

Lexer1.h:

struct SendmailScanner : yyFlexLexer { 
    int yylex(); 
}; 

Lexer2.h:

struct SSHDFailureScanner : yyFlexLexer { 
    int yylex(); 
}; 

Lexer1.l:

%{ 
#include "Lexer1.h" 
%} 

%option c++ 
%option noyywrap 
%option yyclass="SendmailScanner" 
%option prefix="zz" 

%% 
... 

Lexer2.l:

%{ 
#include "Lexer2.h" 
%} 

%option c++ 
%option noyywrap 
%option yyclass="SSHDFailureScanner" 
%option prefix="xx" 

%% 
... 

以上文件不包括#undef yyFlexLexer#define yyFlexLexer ... 指令。 編譯flex生成的文件時,可能不需要這些指令。

希望這會有所幫助