node.js C++扩展build error

violencor 发布于:2015-11-12 22:00 栏目:杂谈 浏览:701 评论:1
在Ubuntu上安装了node.js(源码编译安装),然后开始搞C++扩展,跑网上的一个HelloWorld小demo就没过。

结构: hello.cc、binding.gyp、test_hello.js
代码如下:
hello.cc :

#include <node.h>
#include <v8.h>


using namespace v8;


Handle<Value> Method(const Arguments& args) {
  HandleScope scope;
  return scope.Close(String::New("hello,world"));
}


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


NODE_MODULE(hello, init)


binding.gyp:

{
  "targets": [
    {
      "target_name": "hello",
      "sources": [ "hello.cc" ]
    }
  ]
}

用node-gyp configure是通过的,但是node-gyp build的时候就报错了:
刚开始报了‘Arguments’ does not name a type, 翻开v8.h看了看,在Arguments前面加了internal作用域,这个错没了。
之后的错是‘v8::HandleScope::HandleScope()’ is protected,还是看了头文件后,把HandleScope scope;换成了
                 Isolate* isolate = Isolate::GetCurrent();
                 HandleScope scope(isolate);
之后的错似乎就不会解了(上面两个解得似乎也有问题),错误如下:



 CXX(target) Release/obj.target/hello/hello.o
../hello.cc: In function ‘v8::Handle<v8::Value> Method(const v8::internal::Arguments&)’:
../hello.cc:10:15: error: ‘class v8::HandleScope’ has no member named ‘Close’
  return scope.Close(String::New("hello,world"));
               ^
../hello.cc:10:21: error: ‘New’ is not a member of ‘v8::String’
  return scope.Close(String::New("hello,world"));
                     ^
../hello.cc: In function ‘void init(v8::Handle<v8::Object>)’:
../hello.cc:14:15: error: ‘NewSymbol’ is not a member of ‘v8::String’
  exports->Set(String::NewSymbol("hello"),
               ^
../hello.cc:15:31: error: no matching function for call to ‘v8::FunctionTemplate::New(v8::Handle<v8::Value> (&)(const v8::internal::Arguments&))’
   FunctionTemplate::New(Method)->GetFunction());
                               ^
../hello.cc:15:31: note: candidate is:
In file included from /home/cxy/.node-gyp/4.2.2/include/node/node.h:42:0,
                 from ../hello.cc:1:
/home/cxy/.node-gyp/4.2.2/include/node/v8.h:4349:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Local<v8::Value>, v8::Local<v8::Signature>, int)
   static Local<FunctionTemplate> New(
                                  ^
/home/cxy/.node-gyp/4.2.2/include/node/v8.h:4349:34: note:   no known conversion for argument 1 from ‘v8::Handle<v8::Value>(const v8::internal::Arguments&) {aka v8::Local<v8::Value>(const v8::internal::Arguments&)}’ to ‘v8::Isolate*’
../hello.cc: In function ‘v8::Handle<v8::Value> Method(const v8::internal::Arguments&)’:
../hello.cc:11:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make: *** [Release/obj.target/hello/hello.o] Error 1
make: Leaving directory `/home/cxy/node/v8_test_helloworld/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.16.0-52-generic


求大神指导!  小生实在无力了。
沙发#
发布于:2015-11-16 10:12
唉,没人啊,百度上也没资料,自顶一记,也求个靠谱的vpn
游客

返回顶部