I am not able to run the easiest type of Node.js native extension, a Hello World, and I don't know why.
I am using the example here: http://nodejs.org/api/addons.html#addons_hello_world
node-gyp
runs just fine, but when I try to require
it in node, I get an error:
Error: invalid argument at Object..node (module.js:472:11) at Module.load (module.js:348:31) at Function._load (module.js:308:12) at Module.require (module.js:354:17) at require (module.js:370:17) at repl:1:13 at REPLServer.eval (repl.js:80:21) at repl.js:190:20 at REPLServer.eval (repl.js:87:5) at Interface. (repl.js:182:12)
What is this, and how can I debug errors like this when using native extensions?
Apparently the example now works, after I have wrapped the init
section in an extern "C"
block.
Everything is good now.
Also, if you are by any chance following this example: https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/
Do have in mind that the initialization function you give to NODE_MODULE
must not be static
! It appears that the introspection library or other mechanisms that Node.js uses to register your module, don't support reading (the names of) static functions in C.
Hope this helps everyone having similar issues!
https://github.com/olalonde/node-notify
There is everything explained in the readme.