Electron property added: DLL initialization procedure failed

I am trying to link my C ++ library as a native addition to my electronic application. I can run node -gyp rebuild and create a successful .node file.

But when I try to call it from main.js, I get an error: "Dynamic Link Library (DLL) failed to execute."

My binding.gyp file is as follows:

{ 'targets': [ { # Usual target name/sources, etc. 'target_name': 'myclass', 'sources': [ 'myclass.cc', 'addon.cc' ], 'libraries': ["../libs/api.lib", "../libs/core.lib", "../libs/camera.lib", "../libs/algo.lib", "../libs/ComCtl32.lib", "../../deps/windows/opencv/lib/x64/*.lib", "../../deps/windows/tbb/lib/x64/*.lib"], 'include_dirs': ["<!(node -e \"require('nan')\")"], 'configurations': { 'Debug': { 'msvs_settings': { 'VCCLCompilerTool': { 'RuntimeLibrary': '3' # /MDd }, }, }, 'Release': { 'msvs_settings': { 'VCCLCompilerTool': { 'RuntimeLibrary': '2' # /MD }, }, }, }, },], } 

What could be wrong? Please let me know if you need more information.

+5
source share
2 answers

A few things can go wrong ...

x64 vs. x86

You need to make sure that you are using x86 v x64 correctly. The x64 binary will work, for example, only in the x64 node version. I see that you are directly linking to some x64 libraries, you probably need to conditionally reference the libraries you need based on the architecture you are targeting. And then make sure you get the correct version of the electron.

Dependent dlls

Make sure your dll files are in the right places. Basically, they should be in the same directory or next to exe, which is trying to load the DLL.

It looks like you are using windows, so try using this tool to open your DLL and see what its depen.exe dependencies are

It should be noted that when you rebuild using node -gyp, the dll will only open in electronic mode now, you need to do some magic to make it also load into the node from the command line without further recompilation.

How are you actually trying to load a DLL?

Version

You must have the exact correct versions of node, electronic, and node -gyp. Triple check everything.

I can elaborate on any of these topics if you need detailed information.

+1
source

npm install -g prebuild

cd node_modules / prebuild -t 1.3.1 -r electron

cd node_modules / ref prebuild -t 1.3.1 -r electron

'1.3.1' - electron version

+1
source

Source: https://habr.com/ru/post/1239401/


All Articles