I'm writing a simple node.js addon in C++ using Eclipse CDT. The project has many files and I'd like to use the Eclipse's managed build system.
I can compile a simple addon example with node-waf
, but I can't configure my Eclipse toolchain to build a proper shared library without waf. Waf uses gcc behind the scenes, so I'm sure it's possible.
Which libs should I link to and what kind of options should I pass along to make it work?
Currently I get the following error if I try to require
my lib:
SyntaxError: Unexpected token ILLEGAL
Finally found the answer.
Required compiler flags:
g++
-g
-fPIC
-DPIC
-D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
-D_GNU_SOURCE
-DEV_MULTIPLICITY=0
-I/usr/local/include/node
addon.cc
-c
-o addon.o
Linker flags:
g++ addon.o -o addon.node -shared -L/usr/local/lib
Importand note:
The shared library must have the extension .node
, e.g: foobar.node
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With