2016-02-25 13 views
8

Sto seguendo l'esempio di nan, ma il documention non funziona.Nan build error

mia binding.gyp:

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

e la mia 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) 

Va bene in node-gyp configure, ma quando node-gyp build, segnala gli errori:

../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()); 

mia la versione del nodo è l'ultima 5.7.0 e node-gyp è l'ultima 3.3.0 nan i s più recente 2.2.0. È possibile che un codice che ho usato nell'esempio sia stato deprecato? O cosa devo fare per completare l'esempio ciao? Grazie

+0

Ho lo stesso problema. – InsaneRabbit

risposta

1

Ho appena incontrato lo stesso problema, da quello che posso dire che l'esempio è antiquato. Di seguito ha lavorato per me:

#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) 

In sostanza invece di utilizzare il codice - https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world Ho provato a eseguire il codice da qui - https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world/nan