Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've written a native addon for node.js, compiled it with MSVC++ without node-gyp, and used it successfully on the node REPL and in an application. I'm using x64 node and compiling an x64 addon. I'm trying to get the thing to build with node-gyp. I've gotten node-gyp to generate a Visual Studio solution and compile 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 this:

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've learned that dlopen has something to do with loading dynamic libraries on Linux, but can't find any useful information relevant to node (in particular, on Windows.). This addon requires some third-party dlls, but they are on my path, and again, the addon works fine when I compile it without node-gyp.

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

like image 721
Jake Avatar asked Jul 03 '12 21:07

Jake


1 Answers

It turned out that the problem lay in my use of the NODE_MODULE macro. I had something like this:

NODE_MODULE(SomeAddonName, Init)

But my binding.gyp had this:

"target_name": "totallyDifferentName",

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

Thanks to @TooTallNate for helping me with this!

like image 192
Jake Avatar answered Oct 06 '22 19:10

Jake