将Node.js模块中的Boost与node-gyp链接起来

我试图创build一个node.js加载项,它是一个简单的包装来访问Boost库项目中的perl正则expression式。

我正在运行OSX 10.9.2,而且我也不是一个c ++开发人员,所以工具不熟悉。

我的项目如下所示

boost.cc

#include <node.h> #include <v8.h> #include <boost/regex.hpp> using namespace v8; Handle<Value> Match(const Arguments& args) { HandleScope scope; if (args.Length() < 2) { ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); return scope.Close(Undefined()); } if (!args[0]->IsString()) { ThrowException(Exception::TypeError(String::New("Regex agrument 1 must be a string"))); return scope.Close(Undefined()); } if (!args[1]->IsString()) { ThrowException(Exception::TypeError(String::New("Target agrument 2 must be a string"))); return scope.Close(Undefined()); } v8::String::Utf8Value param0(args[0]->ToString()); v8::String::Utf8Value param1(args[1]->ToString()); std::string sre = std::string(*param0); std::string s = std::string(*param1); try { boost::cmatch matches; boost::regex re(sre, boost::regex::icase); if (boost::regex_match(s.c_str(), matches, re)) { return scope.Close(Boolean::New(true)); } else { return scope.Close(Boolean::New(false)); } } catch (boost::regex_error& e) { ThrowException(Exception::TypeError(String::New("Regex is not a valid regular expression"))); return scope.Close(Undefined()); } return scope.Close(Boolean::New(false)); } void init(Handle<Object> exports) { exports->Set(String::NewSymbol("match"), FunctionTemplate::New(Match)->GetFunction()); } NODE_MODULE(boost, init) 

binding.gyp

 { "targets": [ { "target_name": "boost", "sources": [ "boost.cc" ], "include_dirs": [ "/usr/local/include/boost", ], "libraries": [ "/usr/local/lib/libboost_regex.dylib" ] } ] } 

app.coffee

 addon = require('../addons/boost/build/Release/boost') console.log(addon.match("(?<!street)name", "StreetName")) 

运行node-gyp rebuild –verbose会导致加载项的成功构build。 当运行应用程序虽然我收到以下错误:

 dyld: lazy symbol binding failed: Symbol not found: __ZN5boost9re_detail12perl_matcherIPKcSaINS_9sub_matchIS3_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE14construct_initERKNS_11basic_regexIcSA_EENS_15regex_constants12_match_flagsE Referenced from: <projects dir>/addons/boost/build/Release/boost.node Expected in: dynamic lookup dyld: Symbol not found: __ZN5boost9re_detail12perl_matcherIPKcSaINS_9sub_matchIS3_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE14construct_initERKNS_11basic_regexIcSA_EENS_15regex_constants12_match_flagsE Referenced from: <projects dir>/addons/boost/build/Release/boost.node Expected in: dynamic lookup 

我已经玩了bind.gyp和otool几个小时,但我明显在这里深深的。

在输出otool给我以下内容:

 otool -L build/Release/boost.node build/Release/boost.node: /usr/local/lib/libboost_regex.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 60.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 2577.0.0) 

我用brew安装了boost库(brew install –with-python boost),所有的dynamic库似乎都在那里。

我想我的问题是类似于这一个: 在OSX 10.7.5节点的gyp – dyld:懒惰符号绑定失败:符号未find – 但我没有运气的修复。

我可以得到一个基本的附加运行没有依赖关系,它只是出现我不能链接Boost库正确使用节点gyp等

任何帮助将非常感激!

       

网上收集的解决方案 "将Node.js模块中的Boost与node-gyp链接起来"

答案是使用c ++ 11编译节点附加组件。 bind.gyp的一些调整是所有需要的。

binding.gyp

 { "targets": [ { "target_name": "boost", "sources": [ "boost.cc" ], "include_dirs": [ "/usr/local/include/boost", ], "libraries": [ "/usr/local/lib/libboost_regex.dylib" ], "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' } }] ] } ] }