【发布时间】:2018-05-25 12:13:17
【问题描述】:
我目前正在尝试使用nbind 和universal example 编写一个C++ NodeJS 插件。构建和运行该示例可以完美运行。现在我有两个问题,第一个与一般调试有关,第二个与我的问题有关。
我添加了 RF24 库。构造一个 RF24 对象也可以,但是在 Nodejs 中调用例如 getChannel() 或 printDetails() 函数只会返回
terminated called after throwing an instance of 'int'
npm ERR! Test failed. See above for more details
如何从错误中获取更多详细信息,例如文件和行号?我尝试添加 node-gyp configure --debug build --debug 标志,但构建也只生成一个 Release 文件夹。
我的构建命令如下,就像通用示例中建议的那样。
"build:native": "autogypi -r build && node-gyp -C build/native configure --debug build --debug && copyasm build/native dist"
我正在构建 RPi Zero W (Arm v6)。我当前位于 ./build/native 中的 binding.gyp 如下所示
{
"targets": [
{
"includes": [ "../auto.gypi" ],
"sources": [
"../../src/example.cpp",
"../../libs/RF24-master/RF24.cpp",
"../../libs/RF24-master/utility/RPi/bcm2835.cpp",
"../../libs/RF24-master/utility/RPi/interrupt.cpp",
"../../libs/RF24-master/utility/RPi/spi.cpp"
],
"include_dirs": [
"../../src",
"../../libs/RF24-master"
],
"cflags": [
"-std=c++11",
"-fpermissive"
],
"cflags_cc!": [ "-fno-rtti" ]
}
],
"includes": [
"../auto-top.gypi"
]
}
简化程序example.cpp 看起来像
#include "RF24.h"
#include "example.h"
Example::Example(uint16_t cePin, uint16_t spiBus): cePin(cePin), spiBus(spiBus) {
this->radio = new RF24(cePin, spiBus);
}
uint8_t Example::getChannel() {
return this->radio->getChannel();
}
而对应的headerexample.h看起来像
#ifndef EXAMPLE_H
#define EXAMPLE_H
class Example{
uint8_t cePin = 22, spiBus = 0;
RF24* radio;
public:
Example(uint16_t cePin, uint16_t spiBus);
uint8_t getChannel();
};
#endif
#include "nbind/nbind.h"
NBIND_CLASS(Example) {
construct<uint8_t, uint8_t>();
method(getChannel);
}
所以有两个问题
- 常规和更重要的:如何获得更舒适的 nbind c++ 插件调试选项?
- 更具体到我的问题并与 RF24 相关:为什么在每个 RF24 函数调用中都会出现该错误?
【问题讨论】:
标签: c++ node.js debugging node-gyp