gpt4 book ai didi

c++ - 使用 boost(或与此相关的任何其他库)构建 NodeJs 模块

转载 作者:行者123 更新时间:2023-11-30 02:53:17 26 4
gpt4 key购买 nike

我正在尝试使用一些 boost header 使用 C++ 和 Ubuntu 13.04 构建一个 nodejs 模块,如下所示:

#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 worked if it ends with ok gyp info using node-gyp@0.10.9 gyp info using node@0.10.15 | linux | x64 gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] make: Entering directory /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 error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12) gyp ERR! System Linux 3.8.0-19-generic gyp ERR! command "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! not ok

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

编辑我假设我必须以某种方式编辑我的 binding.gyp 文件以允许编译 boost。该文件目前看起来像这样:

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

最佳答案

对于出现此错误的任何其他人,关键是为 node-gyp 启用异常。在您的 bindings.gyp 文件中,确保包含此内容

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

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

关于c++ - 使用 boost(或与此相关的任何其他库)构建 NodeJs 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18139466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com