Cannot load node.js native addon when building using node -gyp, but it works when building using Visual Studio

I wrote my own addon for node.js, compiled it with MSVC ++ without node -gyp, and successfully used it in node REPL and in the application. I am using x64 node and compiling x64 addon. I am trying to compile this thing with node -gyp. I got node -gyp to create a Visual Studio solution and compiled it, but the addon that comes out does not work. The only error I get is this:

Error: The specified procedure could not be found. at Object.Module._extensions..node (module.js:480:11) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:362:17) at require (module.js:378:17) at repl:1:13 at REPLServer.self.eval (repl.js:111:21) at rli.on.e (repl.js:260:20) at REPLServer.self.eval (repl.js:118:5) at Interface.<anonymous> (repl.js:250:12) 

When I run a script that tries to load the addon, I get the following:

 module.js:480 process.dlopen(filename, module.exports); ^ Error: The specified procedure could not be found. at Object.Module._extensions..node (module.js:480:11) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:362:17) at require (module.js:378:17) at Object.<anonymous> (c:\blah\testheaders.js:1:75) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) 

I found out that dlopen has something to do with loading dynamic libraries on Linux, but cannot find useful information related to node (specifically on Windows.). This addon requires some third-party DLLs, but they are on my way, and again the addon works fine when I compile it without node -gyp.

What do I need to do to figure out how to do this?

+6
source share
1 answer

It turned out that the problem is to use the NODE_MODULE macro. I had something like this:

 NODE_MODULE(SomeAddonName, Init) 

But my bind.gyp had this:

 "target_name": "totallyDifferentName", 

It turns out the target_name in binding.gyp should be the same as the module name (first argument to NODE_MODULE).

Thanks to @TooTallNate for helping with this!

+14
source

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


All Articles