Building Electron Native Extensions using Visual B

2019-07-27 12:20发布

问题:

Where I am currently:

I have began working on a NodeJS native extension I intend to work with Electron, but from previous works I have noted that the build steps for building for just NodeJS are as expected, include the libraries as per instruction and change to output a .dll file with a .node extension.

The problem I am facing:

When compiling my extension, which tried and tested within NodeJS, does not work within an Electron contained instance of NodeJS - from searching around I understand this to be a problem with the header files which I am compiling against etc. The documentation for building with visual studio (not Visual Studio Code) is very sparse and everywhere generally points to using node-gyp - which is something I'm attempting to avoid and build using purely Visual Studio 2015.

For reference, when running the working (in NodeJS) NativeExtension I get the following error (which googling brought me to the conclusion I am compiling against the wrong thing):

ELECTRON_ASAR.js:167 Uncaught Error: Module did not self-register.

Could someone please shed some light on where I may be going wrong? I am a novice when it comes to C++ program structure and compiling methodologies.

回答1:

The documentation for building with visual studio (not Visual Studio Code) is very sparse and everywhere generally points to using node-gyp - which is something I'm attempting to avoid and build using purely Visual Studio 2015.

There is a standard way of compiling native Node modules, and as a self admitted novice it would be unwise to deviate from it. I suggest you read through the Microsoft NodeJS guidelines and get your development environment properly configured to build via node-gyp, once that's working you can start figuring out how to rebuild native Node modules for Electron.