【发布时间】:2013-08-10 23:01:24
【问题描述】:
我正在尝试使用一些 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 it 如果它以 ok gyp info 结束,则使用 node-gyp@0.10.9 gyp info 使用节点@0.10.15 | linux | x64 gyp info spawn 制作 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 错误!建造 错误 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 错误!系统 Linux 3.8.0-19-generic gyp 呃!命令“节点”“/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" ]
} ] }
【问题讨论】:
-
感谢您的编辑。复制的文字有点愚蠢。
-
您是否设法使用 gsoap,我遇到了同样的问题,目前正在调查。