c++扩展初试,但是编译不通过,求解答
发布于 8 年前 作者 moxiaobei2 3077 次浏览 来自 问答

新建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" ]
}
]
}

test.js如下

var addon = require('./build/Release/hello');
console.log(addon.hello());

进行 node-gyp configure build 直接编译的时候出现如下错误,敢问哪位大神也遇到过呢,win环境实在让人神伤啊。。。 2016-01-11_165507.png

4 回复

看报错 官网那个404的地址已经迁移到 http://nodejs.org/dist/v5.0.0/win-x86/node.lib 建议你升级node5.x到最新试试吧

升级一下node-gyp试试

@wssgcg1213 好的。我试下先。

自己总结一下,主要是node-gyp版本问题,删除本身对应的npm 及npm-cache下的node-gyp版本,彻底清掉之后,重新再npm install -g node-gyp拿最新的版本,即可以编译成功。编译时切记c语法问题,不然一个不小心又是不通过了。

回到顶部