如何在本机Node插件中成功链接Flex,Bison和Node.js?

时间:2011-05-20 22:19:00

标签: c++ c node.js bison flex-lexer

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

以下是文件结构的概述:

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.

当我运行一个简单的测试来解析JS字符串时,我收到一个错误

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

注意:我正在使用node-waf构建插件,并且我已将flex和bison生成的文件从[FILE] .c重命名为[FILE] .cc,以便构建脚本选择它们。 / p>

如果你想看一些代码,你可以在这里找到它: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构建脚本(我的解决方案)之外,还可以使用flex ++和bison ++来生成C ++。

2 个答案:

答案 0 :(得分:1)

将文件重命名为.cc通常会导致使用c ++而不是c来构建默认的make规则。这可能意味着lex.yy.c文件中的函数链接错误。我认为你需要弄清楚另一种方法,让节点构建系统识别你的.c文件并使用c而不是c ++正确构建它们

答案 1 :(得分:1)

摆脱extern "C"文件顶部的geto.y。 Flex函数不会通过C-linkage导出。

相关问题