【发布时间】:2017-10-15 06:12:40
【问题描述】:
我正在使用本机 C++ 在电子上制作一个简单的 hello world 应用程序,但出现此 Uncaught Error : error 1114 错误。此错误特别是当项目在 Windows 上运行而在 Fedora 上运行良好时。
package.json:
{
"name": "nodec",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron-packager": "^8.7.0"
}
}
binding.gyp:
{
"targets": [
{
"target_name": "addon",
"sources": [ "addon.cc" ]
}
]
}
addon.cc:
#include <node.h>
namespace demo {
using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
void hello(const FunctionCallbackInfo& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate,"world"));
}
void Init(Local exports) {
NODE_SET_METHOD(exports, "hello", hello);
}
NODE_MODULE(addon, Init)
}
main.js:
const addon = require('./build/Release/addon');
console.log('This should be eight:', addon.hello());
index.html:
<title>My C++ App</title> Hello <script> require('./main.js') </script>
我已经多次配置和构建项目,但在这种情况下似乎没有帮助。
【问题讨论】:
标签: c++ node.js npm electron native