我已经用C ++编写了一些函数来解析csv
文件(Using this parser: https://github.com/AriaFallah/csv-parser)并对其进行处理。现在,我想对基于NodeJS的项目使用(几乎)相同的代码。编译并运行它可以很好地工作(我使用CMakeLists
进行编译),但是当尝试通过node-gyp
(基于nan
进行一些更改)进行编译时,我使用了仅标头的库对于csv
的解析会立即初始化,并由于输入流无效而引发异常。
#include <nan.h>
#include <iostream>
#include <stdexcept>
#include <string>
#include <cstring>
#include "csv-parser.hpp"
#include "SampleData.h"
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace Nan;
using namespace v8;
using namespace aria::csv;
NAN_METHOD(ParseData) {
std::ifstream some_stream("<path1">);
[... lots of stuff]
}
NAN_MODULE_INIT(Initialize) {
NAN_EXPORT(target, ParseData);
}
NODE_MODULE(addon, Initialize);
由于以下原因,编译失败:
make: Entering directory '/home/me/WebstormProjects/nodenative/build'
g++ '-DNODE_GYP_MODULE_NAME=addon' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/home/me/.node-gyp/8.11.4/include/node -I/home/me/.node-gyp/8.11.4/src -I/home/me/.node-gyp/8.11.4/deps/openssl/config -I/home/me/.node-gyp/8.11.4/deps/openssl/openssl/include -I/home/me/.node-gyp/8.11.4/deps/uv/include -I/home/me/.node-gyp/8.11.4/deps/zlib -I/home/me/.node-gyp/8.11.4/deps/v8/include -I../node_modules/nan -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/addon/main.o.d.raw -c -o Release/obj.target/addon/main.o ../main.cpp
In file included from ../main.cpp:6:0:
../csv-parser.hpp: In constructor ‘aria::csv::CsvParser::CsvParser(std::istream&)’:
../csv-parser.hpp:81:84: error: exception handling disabled, use -fexceptions to enable
throw std::runtime_error("Something is wrong with input stream");
^
即使不使用csv-parser.hpp
,也会立即发生这种情况。
谢谢您的任何想法!