的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": "node regex.js"
},
"gypfile": true
}
bindings.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' ],
}]
]
}
]
}
regex.cpp
#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)
仅仅因为#include<boost/regex.hpp>
我在运行此代码时遇到了段错误:
var addon = require('bindings')('boostregex');
console.log(addon.hello()); // 'world'
没有这个包含,插件工作正常..
很奇怪,因为它只是头文件..
Boost库成功编译(尝试过clang和gcc,都可以)
FreeBSD,Node.js v4
Anyidea为什么会出现段错?