node.js - hello world 上的 node-gyp 构建错误

标签 node.js node-gyp

我试图编译node hello world addon当我打电话时 node-gyp configure build 它会生成几个错误。

../binding.cc:6:19: error: unknown type name 'FunctionCallbackInfo'
    void Method(const FunctionCallbackInfo<Value>& args) {
                      ^
../binding.cc:6:39: error: expected ')'
    void Method(const FunctionCallbackInfo<Value>& args) {
                                          ^
../binding.cc:6:12: note: to match this '('
    void Method(const FunctionCallbackInfo<Value>& args) {
               ^
../binding.cc:8:15: error: no matching constructor for initialization of 'v8::HandleScope'
      HandleScope scope(isolate);
                  ^     ~~~~~~~
/***/***/.node-gyp/0.10.36/deps/v8/include/v8.h:473:3: note: candidate constructor not viable: no known conversion from 'v8::Isolate *' to 'const v8::HandleScope' for 1st
          argument
      HandleScope(const HandleScope&);
      ^
/****/***/.node-gyp/0.10.36/deps/v8/include/v8.h:448:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
      HandleScope();
      ^
../binding.cc:9:3: error: use of undeclared identifier 'args'
      args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
      ^
../binding.cc:9:37: error: no member named 'NewFromUtf8' in 'v8::String'
      args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));

可能是什么问题?

最佳答案

问题在于该示例假设您正在运行 Node 0.12,但实际上您正在运行 Node 0.10(从外观上看是 0.10.36)。 Node 0.12 中插件的结构方式发生了重大(向后不兼容)变化。

这是 0.10 兼容版本:https://github.com/joyent/node/blob/aa35564ca1c9f3854bc5f7983f2f00cb51f67ffe/test/addons/hello-world/binding.cc

nan 是一个很棒的包,可以解决 Node 版本之间的许多差异。 .

关于node.js - hello world 上的 node-gyp 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534395/

相关文章:

node.js - Cloudflare SSL 握手因 socket.io 失败

javascript - Sequelize : create is not a function when model is generated from migration

linker - 为什么链接器会更改共享库名称?

javascript - 如何解决 Windows 10 上的 'node-gyp rebuild' 问题?

node.js - TFS 上的 Node 构建问题

linux - 在linux上启动了两个 Node 实例

node.js - 如何访问模型方法?

node.js - 无法在 Windows 上安装 Atom 包

node.js - 什么是 Node gyp?

visual-studio-2010 - node-gyp:无法打开输入文件 'kernel32.lib'