我正在尝试使用一些 boost 标头构建带有 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 如果它以 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! 构建错误 gyp ERR!堆栈错误:make
退出代码失败:2 gyp ERR!ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23) 的堆栈 gyp 错误!堆栈在 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!命令“节点”“/usr/local/bin/node-gyp”“构建”gyp ERR!cwd /home/sam/workspace_cpp/NodeTest/src gyp 错误!节点 -v v0.10.15 gyp 错误!节点-gyp -v v0.10.9 gyp 错误!不好
我在网上找不到任何关于如何让 node-gyp 与其他库(如 boost)一起构建的信息。有人对此有任何见解或经验吗?我的最终目标是使用 gsoap 制作一个 SOAP 模块。
编辑 我假设我必须以某种方式编辑我的 binding.gyp 文件以允许编译 boost。就目前而言,这个文件目前看起来像这样:
{ "targets": [
{
"target_name": "hello",
"sources": [ "NodeTest.cpp" ]
} ] }