1

I am trying to use a custom node package that I wrote in an Electron application and I am having trouble getting the resulting DLL/Node package to initialize. When I launch my Electron application, I get the following error:

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

The DLL being linked is a simple library written in C++ that has one function that takes a double as an input and simply adds one to it, returning the result. To build the C++ library, I use SWIG (http://www.swig.org/) and node-gyp with the following commands:

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

mace_api is the package I am trying to build. mace_api.i, the binding.gyp file, and the source files for my library are defined as follows:

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 takes the C++ source files and basically writes a wrapper that can be used, in this case, by node-gyp to build a Node package. Has anyone tried to use a custom Node module built in this manner in an Electron application? Am I missing something with how SWIG generates a wrapper for my C++ library, or how Electron handles custom Node packages? I am able to link the library with Node, but not with Electron. Any help would be appreciated.

For completeness, below is how I am trying to include and use my package in my Electron application:

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

1 Answers1

0

Have you checked out https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md#manually-building-for-electron

Specifically,

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.

shashi
  • 4,616
  • 9
  • 50
  • 77
  • 1
    When I tried that, I get `The term 'HOME=~/.electron-gyp' is not a recognized name of a cmdlet, function, script file, or operable program.` I should mention that I am running on Windows 10, but get the same issues when running in Ubuntu. – PNolan Oct 28 '16 at 13:11