2016-10-27 17 views
0

我正嘗試使用我在Electron應用程序中編寫的自定義節點包,並且無法獲取生成的DLL /節點包進行初始化。當我啓動我的電子申請,我得到以下錯誤:在Electron中使用自定義節點包

Uncaught Error: A dynamic link library (DLL) initialization routine failed. 

的DLL被鏈接是用C++編寫有一個函數,它的雙重作爲輸入一個簡單的庫,只是增加了一個給它,返回結果。要構建的C++庫,我使用SWIG(http://www.swig.org/)和節點-GYP用下面的命令:

swig -c++ -javascript -node ./src/mace_api.i 
node-gyp clean configure build 

mace_api是我試圖建立包。 mace_api.i的binding.gyp文件,爲我的庫的源文件中定義如下:

mace_api.i

%module MaceAPI 

%{ 
    #include "./mace_api.cpp" 
%} 

%include <windows.i> 
%include "./mace_api.h" 

binding.gyp

{ 
    "targets": [ 
    { 
     "target_name": "mace-api", 
     "sources": [ "./src/mace_api_wrap.cxx" ] 
    } 
    ] 
} 

mace_api.h

#ifndef MACE_API_H 
#define MACE_API_H 

#include <iostream> 
#include <functional> 
using namespace std; 

class MaceAPI 
{ 

public: 
    MaceAPI(); 

    double addOne(double input); 

}; 

#endif // MACE_API_H 

mace_api.cpp

#include "mace_api.h" 

MaceAPI::MaceAPI() 
{ 
} 

double MaceAPI::addOne(double input) 
{ 
    double ret = input + 1.0; 
    return ret; 
} 

SWIG需要C++源文件,並且基本上會編寫一個可用的包裝器,在這種情況下,可以通過node-gyp構建一個Node包。有沒有人試圖在Electron應用程序中使用以這種方式構建的自定義節點模塊?我是否錯過了SWIG如何爲我的C++庫生成封裝,或者Electron如何處理自定義節點包?我可以將庫與Node連接,但不能與Electron連接。任何幫助,將不勝感激。

爲了完整起見,下面就是我正在嘗試包括,用我的包在我的電子申請:

var libMaceTest= require('mace-api/build/Release/mace-api'); 
var test = new libMaceTest.MaceAPI(); 
console.log(test.addOne(5)); 

回答

0

你檢查出https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md#manually-building-for-electron

具體來說,

Manually building for Electron

If you are a developer developing a native module and want to test it against Electron, you might want to rebuild the module for Electron manually. You can use node-gyp directly to build for Electron:

cd /path-to-module/ HOME=~/.electron-gyp node-gyp rebuild 
--target=1.2.3 --arch=x64 --dist-url=https://atom.io/download/atom-shell 

The HOME=~/.electron-gyp changes where to find development headers. The --target=1.2.3 is version of Electron. The --dist-url=... specifies where to download the headers. The --arch=x64 says the module is built for 64bit system.

+0

當我tr ied,我得到了'HOME =〜/ .electron-gyp'這個術語不是cmdlet,函數,腳本文件或可操作程序的公認名稱。「我應該提到,我在Windows 10上運行,但得到在Ubuntu中運行時遇到同樣的問題。 – PNolan