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

Building NodeJs module with boost (or any other library for that matter)

本文关键字:任何 其他 boost 构建 NodeJ 模块 使用      更新时间:2023-10-16

我正试图用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如果它以ok gyp信息结束,使用node-gyp@0.10.9gyp信息使用node@0.10.15|linux|x64 gyp信息生成生成gyp信息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.onext处的堆栈(child_process.js:789:12)gyp ERR!系统Linux 3.8.0-19通用程序呃!命令"node"/usr/local/bin/node gyp"build"gyp ERR!cwd/home/sam/workspace_cpp/NodeTest/src gyp ERR!节点-v v0.10.15 gyp呃!节点gyp-v v0.10.9 gyp ERR!不正常

我在网上找不到任何关于如何让node-gyp与其他库(如boost)一起构建的信息。有人对此有任何见解或经验吗?我的最终目标是使用gsoap制作一个SOAP模块。

编辑我假设我必须以某种方式编辑我的binding.gyp文件,以便编译boost。目前,这个文件看起来是这样的:

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

对于其他出现此错误的人,关键是为节点gyp启用异常。在bindings.gyp文件中,请确保包含此

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

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

相关文章: