Я использую библиотеку nbind
, и я в настоящее время создаю обещание на c ++, которое будет использоваться в электронном приложении.
Пока я следую документация инструкция и я создал файл ./src/cpp/promice.h
:
#ifndef PROMICE
#define PROMICE
class MyPromice {
public:
MyPromice(){};
~MyPromice(){};
void exec();
};
#endif
И мой ./src/cpp/promice.cpp
:
#include"promice.h"
#include <iostream>
#include<thread>
#include <chrono>
void MyPromice::exec(){
std::this_thread::sleep_for(std::chrono::milliseconds(200));
std::cout << "Executinh Code" << std::endl;
}
#include "nbind/nbind.h"
NBIND_CLASS(MyPromice) {
method(exec);
}
И мой package.json
это:
{
"name": "electron-cpp-bindings",
"version": "1.0.0",
"description": "A simple test using C++ bindings on an electron app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ./src/",
"autogypi": "autogypi",
"node-gyp": "HOME=~/.electron-gyp node-gyp --target=v5.0.6 --arch=x64 --dist-url=https://electronjs.org/headers",
"emcc-path": "emcc-path",
"copyasm": "copyasm",
"ndts": "ndts",
"electron-version": "electron -v",
"rebuild": "HOME=~/.electron-gyp node-gyp rebuild --target=v5.0.6 --arch=x64 --dist-url=https://electronjs.org/headers"
},
"author": "Dimitrios Desyllas",
"license": "MIT",
"devDependencies": {
"electron": "^5.0.6",
"electron-rebuild": "^1.8.5"
},
"dependencies": {
"autogypi": "^0.2.2",
"nbind": "^0.3.15",
"node-gyp": "^5.0.2"
}
}
И у меня ./src/index.js
:
const { app, BrowserWindow, ipcMain } = require('electron');
const env = process.env.NODE_ENV || 'production';
const nbind = require('nbind');
const lib = nbind.init().lib;
const MyPromice=lib.MyPromice;
// See https://stackoverflow.com/a/33067955, by Stijn de Witt
function moduleAvailable (name) {
try {
require.resolve (name);
return true;
} catch (e) {
// empty
}
return false;
}
// Query for your particular module
if (moduleAvailable ("electron-debug")) require ("electron-debug") ({showDevTools:false});
// Generic on development configuration
if (env === 'dev' || env === 'debug') {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
}
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow();
mainWindow.setMenu(null);
mainWindow.maximize();
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/ui/index.html`);
mainWindow.on('closed', () => {
mainWindow = null;
});
MyPromice.exec();
};
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
app.on('before-quit', () => {
if (xmpp) {
xmpp.disconnect();
}
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});
process.on('unhandledRejection', (reason, p) => {
console.error('Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason);
});
process.on('SIGINT', () => {
if (xmpp) {
xmpp.disconnect();
}
process.exit(0);
});
Но по какой-то причине при сборке с:
npm run -- node-gyp configure build 2> ~/error.txt
я получаю следующий поток ошибок, как видно из здесь (я использовал gist из-за длины вывода, из-за которого мой браузер зависал).Кроме того, команда:
npm run rebuild
Возвращает следующий вывод, как показано в здесь
Насколько я понимаю, это кажется некоторой ошибкой компоновки.Вы знаете, как я могу это исправить?