我試圖創建一個node.js加載項,它是一個簡單的包裝來訪問Boost庫項目中的perl正則表達式。在node.js模塊中使用node-gyp鏈接增強
我正在運行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導致加載項的成功構建。當運行應用程序,雖然我收到以下錯誤:
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
我與binding.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安裝--without-python的提升)和所有的動態庫似乎在那裏。
我的問題,我猜是類似於這個:node-gyp on OSX 10.7.5 -- dyld: lazy symbol binding failed: Symbol not found - 但我沒有運氣的修復。
我可以得到一個基本的附加不依賴運行,它只是出現使用節點GYP等
任何幫助,將不勝感激,我無法正常鏈接升壓庫!