使用boost构建NodeJ模块(或任何其他库)
Building NodeJs module with boost (or any other library for that matter)
我正试图用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
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 为什么 c++ 中的 main() 函数不采用除 int 和 void 之外的任何其他返回类型
- 如何在不进行任何其他修改的情况下"pretty print" C++的XML字符串?
- 如何对 int 变量应用验证,使其仅接受整数数据,并且在任何其他数据的情况下不会出错?
- 如何计算该程序的复杂性?是否有任何其他复杂性较低的解决方案
- 如何使用"std::multimap"或任何其他容器对多个值进行排序?
- 如何在任何其他全局变量或静态变量之前创建/构造类实例
- SSO在STD :: String以外的任何其他标准库容器中使用
- OpenCV将一种颜色转换为任何其他颜色
- 如何使用QT或Linux上的任何其他CPP框架播放WMA音频文件
- 在构造函数以外的任何其他位置访问相机时,我的相机指针返回 null
- "size_t"是否始终是"vector<int>::size_type"或任何其他容器类型的别名?
- 来自没有默认构造函数的超级类的子类,而无需调用任何其他构造函数
- 我们还能使用任何其他方法来访问Android中的C 代码,而不是使用JNI访问C 代码
- 如何在 ubuntu 中单击任何其他歌曲后停止当前播放的歌曲
- 如何检查数组是否等于任何其他数组C++
- 我如何使用OCI或任何其他LIB登录Oracle作为SYS帐户
- 默认的Qt控制台应用程序不会"Hello World"...或做任何其他事情
- -fno elide构造函数是否包含在-O0或任何其他优化级别中