如何在原生 Node 插件中成功链接 Flex、Bison 和 Node.js
How can I successfully link Flex, Bison, and Node.js in a native Node addon?
我正在尝试使用Flex/Bison编写本机Node.js解析器。插件有三个部分:词法分析器、解析器和 node/v8 接口。词法分析器和解析器在开始时运行良好(我使用 g++ 编译词法分析器/解析器,并包含必要的词法分析器函数,如下所示:http://tldp.org/HOWTO/Lex-YACC-HOWTO-5.html)。当我将 node/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,以便构建脚本拾取它们。
如果你想看到一些代码,你可以在这里找到它: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++。
文件重命名为 .cc 通常会导致默认的 make 规则使用 C++ 而不是 C 构建。这可能意味着lex.yy.c文件中的函数链接错误。我认为您需要找出另一种方法,使节点构建系统识别您的 .c 文件并使用 c,而不是 c++ 正确构建它们
删除geto.y
文件顶部的extern "C"
。 弹性函数未通过 C 链接导出。
- node-gyp 在 macOS 上未正确链接库
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- node-gyp 的先有鸡还是先有蛋的问题:指向依赖项中的头文件
- 在 ubuntu 上安装 node js pulsar 客户端
- 如何使用 Node-addon-API 实现 node-nan 回调
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- NodeJS:node-gyp 编译与等效的 gcc -lm 选项
- 调用'Node'构造函数是不明确的
- 解释通过 lex/flex 实现 C/C++嵌套的"#include "Header""语法?
- Bison/flex 在识别规则后等待输入
- 为什么我得到变量"Node"不是类型名称错误
- 野牛/flex:计算器将双精度值解释为整数,所以我添加了 YYSTYPE 双精度 #define 但我有多个编译错误
- Cmake with Flex/Bison on windows
- 在 node.js 中将缓冲区从 C++ 转换为 UTF-8 字符串
- 如何从 node-ffi 调用 c++ 中以结构向量作为参数的方法?
- 使用 Node.js N-API 调用 C 函数时,不会显示预期的输出
- 给一个图 G 找到此图中的所有节点 blob,以便 node.color 属性 = 特定颜色
- 为什么 const YAML::Node 对象的行为不像 yaml-cpp 中的类似值的对象?
- 无法使用 'const Node *' 类型的右值初始化 'Node *' 类型的变量
- 如何在原生 Node 插件中成功链接 Flex、Bison 和 Node.js