gpt4 book ai didi

electron - Electron 中的节点插件 (C++)

转载 作者:行者123 更新时间:2023-12-02 21:39:00 25 4
gpt4 key购买 nike

我正在尝试使用 Electron 和 Node JS 将 C++ 与 HTML 集成。但是我对 NODE_MODULE_VERSION 感到困惑。我有一个像 binding.gyp 这样的例子。

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

还有一个 hello.cc

// hello.cc
#include <node.h>

namespace demo {

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;

void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}

void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}

NODE_MODULE(addon, init)

} // namespace demo

在node-gyp配置构建之后,它们在node上运行良好

const addon = require('./package/build/Release/addon');
addon.hello();

但是当我将它与Electron结合起来时,出现了问题。 enter image description here

我已经阅读了 Electron 和 NodeJS 的 API。有些人告诉我安装 nvm 来更改 NodeJS 的版本,还有人建议我安装 Electron-build。我尝试过,但他们不起作用。(我认为它会如果它们起作用就会很奇怪)。我认为问题在于nodejs的版本。但是我的节点是v7.7.4!那么,我如何更新模块的版本...谢谢~

最佳答案

正如 @pergy 提到的,你应该使用 --taget 选项来构建,该选项指向 Electron 中使用的正确的 iojs(node) 版本。

在此处查看工作示例(Windows)。 https://github.com/weliwita/electron-edge-sample/tree/42996881/node-addons-c-in-electron

关于electron - Electron 中的节点插件 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42996881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com