使用boost(或任何其他库)构建NodeJs模块

时间:2013-08-09 02:58:45

标签: c++ node.js boost module

我正在尝试用C ++和Ubuntu 13.04构建一个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 it   使用node-gyp@0.10.9 gyp info以ok gyp信息结束工作   使用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!建立   错误gyp ERR!堆栈错误:make失败并退出代码: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! System Linux 3.8.0-19-通用gyp   呃!命令“node”“/ usr / local / bin / node-gyp”“build”gyp ERR! CWD   / home / sam / workspace_cpp / NodeTest / src gyp ERR! node -v v0.10.15 gyp   呃! node-gyp -v v0.10.9 gyp ERR!不行

我无法在网上找到有关如何使用其他库(如boost)构建node-gyp的内容。有没有人对此有任何见解或经验?我的最终目标是使用gsoap创建一个SOAP模块。

修改 我假设我必须以某种方式编辑我的binding.gyp文件以允许编译boost。就目前而言,此文件目前如下所示:

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

1 个答案:

答案 0 :(得分:3)

对于有此错误的任何其他人,关键是启用node-gyp的例外。在bindings.gyp文件中,请确保包含此

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

我在此论坛帖子中找到了我的解决方案:GitHub