2016-02-25 28 views
8

Podążam za przykładem nan, ale documention nie działa.Błąd kompilacji Nan

mój binding.gyp:

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

i mój 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) 

Jest OK w node-gyp configure, ale kiedy node-gyp build, zgłasza błędy:

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

mój wersja węzła jest najnowszą wersją 5.7.0, a węzeł-gyp jest najnowszą wersją 3.3.0 nan i najnowszy 2.2.0. Czy jest możliwe, że niektóre kod użyty w przykładzie ma przestarzałe? Co powinienem zrobić, aby dokończyć przykład Hello? Dzięki

+0

mam ten sam problem. – InsaneRabbit

Odpowiedz

1

Po prostu wpadłem na ten sam problem, z tego, co mogę powiedzieć, że przykład jest przestarzały. Następujące pracował dla mnie:

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

Zasadniczo zamiast przy użyciu kodu z - https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world Próbowałem uruchomiony kod tutaj - https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world/nan