Hi
I am new to Node.js, but need to call a C++ function from Node.js program and get the return value from the call.
I tried to follow this example http://blog.scottfrees.com/c-processing-from-node-js
But ran into errors when I installed JS modules( see output log below)
/iotProj/cppfromjs/nodecpp-demo# npm install -g node-gyp
And the makefile could not run due to compiler option "-Wc++11-extensions"
nodecpp-demo/Makefile at master · freezer333/nodecpp-demo · GitHub
g++ -g -Wall -Wc++11-extensions -std=c++11 -o rainfall rainfall.cc rainfall_test.cc
Wonder if this is the right way to reach my goal, solve the node-gyp module errors and upgrade C++ compiler to version 11 and continue with this example, or
if there is alternative way to call a C++ function from Node.js?
Any advise is appreciated!
Thanks
Jade Dragon
root@galileo:/iotProj/cppfromjs/nodecpp-demo/cpp# node-gyp configure build
gyp info it worked if it ends with ok
gyp info using node-gyp@3.2.1
gyp info using node@0.10.38 | linux | ia32
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/iotProj/cppfromjs/nodecpp-demo/cpp/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/root/.node-gyp/0.10.38/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/root/.node-gyp/0.10.38',
gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=node.lib',
gyp info spawn args '-Dmodule_root_dir=/iotProj/cppfromjs/nodecpp-demo/cpp',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/iotProj/cppfromjs/nodecpp-demo/cpp/build'
CXX(target) Release/obj.target/rainfall/rainfall.o
CXX(target) Release/obj.target/rainfall/rainfall_node.o
../rainfall_node.cc: In function 'void WorkAsyncComplete(uv_work_t*, int)':
../rainfall_node.cc:53:40: error: no matching function for call to 'v8::HandleScope::HandleScope(v8::Isolate*&)'
v8::HandleScope handleScope(isolate);
^
../rainfall_node.cc:53:40: note: candidates are:
In file included from /home/root/.node-gyp/0.10.38/src/node.h:62:0,
from ../rainfall_node.cc:1:
/home/root/.node-gyp/0.10.38/deps/v8/include/v8.h:473:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
HandleScope(const HandleScope&);
^
/home/root/.node-gyp/0.10.38/deps/v8/include/v8.h:473:3: note: no known conversion for argument 1 from 'v8::Isolate*' to 'const v8::HandleScope&'
/home/root/.node-gyp/0.10.38/deps/v8/include/v8.h:448:3: note: v8::HandleScope::HandleScope()
HandleScope();
....
rainfall.target.mk:89: recipe for target 'Release/obj.target/rainfall/rainfall_node.o' failed
make: *** [Release/obj.target/rainfall/rainfall_node.o] Error 1
make: Leaving directory '/iotProj/cppfromjs/nodecpp-demo/cpp/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Linux 3.8.7-yocto-standard
gyp ERR! command "node" "/usr/bin/node-gyp" "configure" "build"
gyp ERR! cwd /iotProj/cppfromjs/nodecpp-demo/cpp
gyp ERR! node -v v0.10.38
gyp ERR! node-gyp -v v3.2.1
gyp ERR! not ok
root@galileo:/iotProj/cppfromjs/nodecpp-demo/cpp#