build立NodeJs模块(或任何其他库)

我想用C ++和Ubuntu 13.04构build一个nodejs模块,使用如下所示的一些boost头文件:

#include <iostream> #include <string> #include <node/node.h> #include <v8.h> #include <boost/lexical_cast.hpp> using namespace std; using namespace v8; Handle<Value> Method(const Arguments& args) { HandleScope scope; std::string foobar = "8"; return scope.Close(String::New("world")); } void init(Handle<Object> exports){ exports->Set(String::NewSymbol("Hello"), FunctionTemplate::New(Method)->GetFunction()); } NODE_MODULE(hello, init) 

但是,使用node-gyp进行编译时,出现以下错误:

sam @ ubuntu:〜/ workspace_cpp / NodeTest / src $ node-gyp build gyp info如果以ok结束,它就会工作gyp info使用node-gyp@0.10.9 gyp info使用node@0.10.15 | linux | x64 gyp info spawn make gyp info spawn args ['BUILDTYPE = Release','-C','build'] make:进入目录/home/sam/workspace_cpp/NodeTest/src/build' CXX(target) Release/obj.target/hello/NodeTest.o In file included from /usr/include/boost/numeric/conversion/converter.hpp:14:0, from /usr/include/boost/numeric/conversion/cast.hpp:33, from /usr/include/boost/lexical_cast.hpp:66, from ../NodeTest.cpp:13: /usr/include/boost/numeric/conversion/converter_policies.hpp: In member function 'void boost::numeric::def_overflow_handler::operator()(boost::numeric::range_check_result)': /usr/include/boost/numeric/conversion/converter_policies.hpp:162:31: error: exception handling disabled, use -fexceptions to enable make: *** [Release/obj.target/hello/NodeTest.o] Error 1 make: Leaving directory / home / sam / workspace_cpp / NodeTest / src / build'gyp ERR! 构build错误gyp ERR! 堆栈错误:使用退出代码失败:2 gyp ERR! 堆栈在ChildProcess.onExit(/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23)gyp ERR! 堆栈在ChildProcess.EventEmitter.emit(events.js:98:17)gyp ERR! 堆栈在Process.ChildProcess._handle.onexit(child_process.js:789:12)gyp ERR! 系统Linux 3.8.0-19-generic gyp ERR! 命令“node”“/ usr / local / bin / node-gyp”“build”gyp ERR! cwd / home / sam / workspace_cpp / NodeTest / src gyp ERR! node -v v0.10.15 gyp ERR! node-gyp -v v0.10.9 gyp ERR! 不好

我找不到任何关于如何让node-gyp与其他库(如boost)一起构build的Web上的任何东西。 有没有人有这方面的见解或经验? 我的最终目标是使用gsoap制作一个SOAP模块。

编辑我假设我必须以某种方式编辑我的binding.gyp文件,以允许编译提升。 当它坐,这个文件目前看起来像这样:

 { "targets": [ { "target_name": "hello", "sources": [ "NodeTest.cpp" ] } ] } 

对于有这个错误的其他人,关键是启用node-gyp的exception。 在您的bindings.gyp文件中,确保包含这个

 ... 'cflags!': [ '-fno-exceptions' ], 'cflags_cc!': [ '-fno-exceptions' ] ... 

我在这个论坛发现我的解决scheme: GitHub