2016-02-25 4 views
8

Я следую примеру nan, но documention не работает.Ошибка сборки Nan

мой binding.gyp:

{ 
    "targets":[ 
    { 
     "target_name": "hello", 
     "sources": ["hello.cpp"], 
     "include_dirs": [ 
     "<!(node -e \"require('nan')\")" 
     ] 
    } 
    ] 
} 

и мой hello.cpp:

#include <nan.h> 

using namespace v8; 

NAN_METHOD(Method) { 
    NanScope(); 
    NanReturenValue(String::New("world")); 
} 

void Init(Handle<Object> exports) { 
    exports->Set(NanSymbol("hello"), FunctionTemplate::New(Method)->GetFunction()); 
} 

NODE_MODULE(hello, Init) 

Это нормально в node-gyp configure, но когда node-gyp build, он сообщает об ошибках:

../hello.cpp:10:9: error: use of undeclared identifier 'NanScope' 
    NanScope(); 
    ^
../hello.cpp:11:33: error: no member named 'New' in 'v8::String' 
    NanReturenValue(String::New("world")); 
        ~~~~~~~~^ 
../hello.cpp:15:18: error: use of undeclared identifier 'NanSymbol' 
exports->Set(NanSymbol("hello"), FunctionTemplate::New(Method)->GetFunction()); 
      ^
../hello.cpp:15:60: error: cannot initialize a parameter of type 'v8::Isolate *' with an lvalue of type 'Nan::NAN_METHOD_RETURN_TYPE (Nan::NAN_METHOD_ARGS_TYPE)' 
exports->Set(NanSymbol("hello"), FunctionTemplate::New(Method)->GetFunction()); 

мой версия узла - последняя версия 5.7.0, а node-gyp - последняя версия 3.3.0 nan i последний 2.2.0. Возможно ли, что какой-то код, который я использовал в примере, устарел? Или что мне делать, чтобы заполнить пример hello? Спасибо

+0

У меня такая же проблема. – InsaneRabbit

ответ

1

Я просто столкнулся с той же проблемой, из чего я могу сказать, что пример устарел. Следующие работал для меня:

#include <nan.h> 

void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) { 
    info.GetReturnValue().Set(Nan::New("world").ToLocalChecked()); 
} 

void Init(v8::Local<v8::Object> exports) { 
    exports->Set(Nan::New("hello").ToLocalChecked(), 
       Nan::New<v8::FunctionTemplate>(Method)->GetFunction()); 
} 

NODE_MODULE(hello, Init) 

В принципе, вместо того, чтобы использовать код из - https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world Я попытался запустить код здесь - https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world/nan