node.js - 需要使用电子应用程序创建节点原生模块
问题描述
我正在创建一个包含本机模块的简单电子应用程序。我已经包含了一些来自 c++ 应用程序的静态库。这是我的 binding.gyp 文件和https://nodejs.org/dist/latest/docs/api/addons.html中提到的创建的 hello.cc 文件这是我的 binding.gyp 文件
binding.gyp:
"targets": [
{
"target_name": "myext",
"libraries": [
"/Users/rsivaram/logitech/obs-studio/deps/w32-pthreads/libpthreadGC2.a",
"/Users/rsivaram/logitech/obs-studio/build/plugins/obs-x264/libobs-x264-util.a",
"/Users/rsivaram/logitech/obs-studio/build/plugins/mac-syphon/libsyphon-framework.a",
"/Users/rsivaram/logitech/obs-studio/build/deps/file-updater/libfile-updater.a",
"/Users/rsivaram/logitech/obs-studio/build/deps/libcaption/libcaption.a",
"/Users/rsivaram/logitech/obs-studio/build/deps/media-playback/libmedia-playback.a",
],
"cflags!": [ "-fno-exceptions" ],
"cflags": [ "-std=c++11" ],
"cflags_cc!": [ "-fno-exceptions" ]
}
]
}
这是我的 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").ToLocalChecked());
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
} // namespace demo
“npm install”工作正常,但是我无法使用“npm start”运行应用程序。我得到的错误
1."identifier "v8" is undefined" in the hello.cc file.
2. "Module did not self-register <abs path of the app>/electron-quick-start/build/Release/myext.node "
如何创建 hello.cc 文件。请告诉我。谢谢
解决方案
推荐阅读
- javascript - PHP单击链接而不是行切换
- c# - 4.10 带有 NuGet 包参考的插件无法正确部署
- git - 掌舵点存储库到 monorepo 包?
- angular - 带有 Jest 单元测试的 Angular 6
- mysql - 两个表左连接但是如果我在表中有额外的行那么它应该是空的
- c# - C#自动化多行字符串修剪
- sprite-kit - 如何使用 Spritekit 实现流畅的同时运行和跳跃动作,如超级马里奥
- python - f.写错误。必须是 str 而不是 resultnet
- javascript - 在 mongodb 中使用 $inc 和 $addToSet
- python - 如何解决 pymysql.err.ProgrammingError: 1064 - 在 mysql 上保存数据?