我如何成功链接本地Node插件中的Flex,Bison和Node.js?

我正在尝试使用Flex / Bison编写本地Node.jsparsing器。 插件有三个部分:词法分析器,parsing器和节点/ v8接口。 词法分析器和parsing器在开始时运行良好(我使用g ++编译词法分析器/parsing器,并包含必要的词法分析器函数,如下所示: http : //tldp.org/HOWTO/Lex-YACC-HOWTO-5.html ) 。 当我将node / v8部分添加到混音中时,我最终得到了在词法分析器代码中定义的函数缺less的符号错误。

以下是文件结构的概述:

File A: Lexer file, automatically generated by flex from the lexer rules I wrote. File B: The parser file, includes the extern "C" { [lexer functions] } and a function called parse(std::string). parse() calls some yy_functions, which are defined in the lexer, and returns a c++ data structure representing the parsed data. File C: This is the node/v8 part. There is a header file with the prototype for B's parse() function. When JS calls a certain function, the data is converted to a c++ string and passed to the parse() function in File B. 

当我运行一个简单的testing来parsingJSstring时,我得到一个错误说

node: symbol lookup error: /home/monty/projects/flex_bison/GetObj_Request_Parser/build/default/GetObjParser.node: undefined symbol: yy_scan_string

注意:我使用node-waf来构build插件,并且我已经将由flex和bison生成的文件从[FILE] .c重命名为[FILE] .cc,以便构build脚本将其选中。

如果你想看到一些代码,你可以在这里find它: https : //github.com/IDX-io/GetObj_Request_Parser (查看src / buildstuffs目录)。

 File A = src/buildstuffs/lex.yy.c[c] File B = src/buildstuffs/geto.tab.c[c] File C = src/buildstuffs/GetObjParser.cc Test = test.js 

谢谢!

[编辑]而不是使用两个不同的编译器,搞乱node-waf构build脚本(我的解决scheme),可能会使用flex ++和bison ++来生成C ++。

将文件重命名为.cc通常会导致使用c ++而不是c来构build默认的make规则。 这可能意味着链接在lex.yy.c文件中的函数上是错误的。 我认为你需要找出另一种方法来使节点构build系统识别你的.c文件,并用c编译,而不是c ++

摆脱geto.y文件顶部的extern "C" 。 Flex函数不会使用C-Link导出。

Interesting Posts