Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build node.js addon without node-waf

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
like image 915
erenon Avatar asked Jul 12 '11 09:07

erenon


1 Answers

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

like image 53
erenon Avatar answered Sep 27 '22 22:09

erenon