C++ 带有node.js加载项的Boost库-segfault
package.json:C++ 带有node.js加载项的Boost库-segfault,c++,node.js,boost,freebsd,boost-regex,C++,Node.js,Boost,Freebsd,Boost Regex,package.json: { "name": "BoostRegexJS", "version": "0.0.1", "description": "Boost::Regex API for node.js", "main": "regex.js", "private": true, "dependencies": { "bindings": "~1.2.1", "nan": "^2.0.0" }, "scripts": { "test"
{
"name": "BoostRegexJS",
"version": "0.0.1",
"description": "Boost::Regex API for node.js",
"main": "regex.js",
"private": true,
"dependencies": {
"bindings": "~1.2.1",
"nan": "^2.0.0"
},
"scripts": {
"test": "node regex.js"
},
"gypfile": true
}
绑定.gyp
{
"targets": [
{
"target_name": "boostregex",
"sources": [ "regex.cpp" ],
"include_dirs": [
"~/boost/include",
"<!(node -e \"require('nan')\")"
],
"libraries": [
"~/boost/lib/libboost_regex.so"
],
"cflags_cc!": [ "-fno-rtti", "-fno-exceptions" ],
"cflags!": [ "-fno-exceptions" ],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++', '-v'],
'OTHER_LDFLAGS': ['-stdlib=libc++'],
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
}
}],
['OS!="win"', {
'include_dirs': [ 'config/win' ],
'cflags+': [ '-std=c++11' ],
'cflags_c+': [ '-std=c++11' ],
'cflags_cc+': [ '-std=c++11' ],
}]
]
}
]
}
如果不包括这些,插件就可以正常工作
奇怪,因为它只是头文件
编译成功的Boost库(尝试了clang和gcc,都还可以)
FreeBSD,Node.js v4
知道为什么是SEGFULT吗?你能得到堆栈跟踪吗?还有可能这些头文件与您链接的boost版本不同吗?@harmic:我只有node.core转储文件。头文件和库文件是通过编程方式生成/复制到同一个目录中的,因此可以确定是同一个版本。安装gdb,然后用它打开核心转储文件。您可以打印堆栈跟踪(命令bt)。可能会给你一个机会clue@harmic:明白了,不是自以为是的:(gdb)核心节点。核心节点是由“节点”生成的。程序以信号11终止,分段故障#0 0x0000000000000000英寸??()
#include <nan.h>
#include <string>
#include <boost/regex.hpp>
void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(Nan::New("worldd").ToLocalChecked());
}
void Init(v8::Local<v8::Object> exports) {
exports->Set(Nan::New("hello").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(Method)->GetFunction());
}
NODE_MODULE(boostregex, Init)
var addon = require('bindings')('boostregex');
console.log(addon.hello()); // 'world'