我正在构建一个本机C ++ nodejs模块。我在windows中开发它,现在我想在linux上运行它。编译器成功完成。但是当我跑步的时候
require('smartparser')
,我收到以下错误:
var a = require('smartparser')
Error: .../node_modules/smartparser/build/Release/smartparser.node: undefined symbol: _ZN2v86String9NewSymbolEPKci
at Module.load (module.js:356:32)
我正在使用Debian (Arch: i386)
和GCC-4.7
。
节点版本:v0.11.3-pre
NPM版本:1.3.10
我也收到以下警告:
make: warning: Clock skew detected. Your build may be incomplete.
但经过一番研究后,我发现这是错误的当地时间造成的。
EDIT2:代码
{
"author": "deepsy@gmail.com",
"targets": [
{
"target_name": "smartparser",
"sources": [ "lib/handler.cpp", "lib/analyzer.cpp", "lib/parser.cpp" ],
"cflags": [
"-std=c++11"
]
}
]
}
.cpp的
Handle<Value> parseHandler(const Arguments& args) {
HandleScope scope;
bool validArguments =
args[0]->IsString() &&
args[1]->IsString() &&
args[2]->IsNumber() &&
args[3]->IsFunction();
if (!validArguments) {
return ThrowException(Exception::TypeError(
String::New("Invalid arguments! Pass the arguments in the following order: {string} text, {string} title, {int} outputlength, {function} callback.")));
}
Local<Array> nodes = Parser(std::string(*String::Utf8Value(args[0]->ToString())),
std::string(*String::Utf8Value(args[1]->ToString())),
int(args[2]->Int32Value()));
const unsigned argc = 2;
Local<Value> argv[argc] = {
Local<Value>::New(Null()),
nodes
};
Local<Function> callback = Local<Function>::Cast(args[3]);
callback->Call(Context::GetCurrent()->Global(), argc, argv);
return Undefined();
}
Local<Array> Parser(std::string input, std::string title, int sentenceLimit)
{
Local<Array> nodes = Array::New();
Local<Object> node_obj;
std::size_t pos = 0;
std::size_t closePos = -1;
std::size_t openPos = -1;
int tagID = -1;
int lastTag = -1;
int lastAppended = -1;
// Output array iterator
int id = 0;
while ((pos = input.find('<', pos)) != std::string::npos) {
pos++;
switch (tagID = tagDetect(&input[pos])) {
case Tags::Closing:
// determine what kind of closing tag is
tagID = tagDetect(&input[pos + 1]);
// Is this the closure of the last tag
if (tagID == lastTag && (pos - openPos > MIN_TEXT_LENGTH || lastTag != Tags::Paragraph)) {
// If two tags of same kind are used in sequence skip second
if (lastAppended == lastTag) {
continue;
}
// Create new object in the array
// Example:
// { tag: 2, content: "Some content" }
node_obj = Object::New();
node_obj->Set(tag_symbol, Integer::New(lastTag));
node_obj->Set(data_symbol, String::New(
analyzer.getSummary(title,
input.substr(openPos + (lastTag > 1 ? 3 : 2), pos - openPos - (lastTag > 1 ? 3 : 2) - 1),
sentenceLimit).c_str()));
nodes->Set(id++, node_obj);
lastAppended = lastTag;
continue;
}
// Clear useless tags
input.erase(pos - 1, input.find('>', pos - 1) - pos + 2);
break;
// Sets a opening tag in the tag detect
case Tags::Paragraph:
case Tags::Heading:
openPos = pos;
lastTag = tagID;
break;
default:
// Clear useless tags
input.erase(pos - 1, input.find('>', pos - 1) - pos + 2);
break;
}
}
// Remove last element from array if its heading elements
if (lastTag == Tags::Heading) {
nodes->Delete(id - 1);
}
return nodes;
}