我正在为nodejs开发C ++插件。这是一个概率过滤器。我需要做的是将现有的c ++库绑定到nodejs。 我正在按照https://nodejs.org/docs/latest/api/addons.html#addons_wrapping_c_objects
中文档的说明进行操作我在github中还有另一个示例,向我展示了c ++中的概率过滤器如何绑定到nodejs:https://github.com/bbondy/bloom-filter-cpp。
我尝试将自己的c ++库转换为nodejs插件。现在我已经完成了编码,我尝试使用binding.gyp单独构建它。但是总会有一个错误: error
但是我确实在该类中包含SimdBlockFilter: 这是simd_block_wrap.h的代码:
#ifndef simd_block_wrap_hpp
#define simd_block_wrap_hpp
#include <node.h>
#include <node_object_wrap.h>
#include "SimdBlockFilter.h"
namespace simd_block_wrap {
class simd_block_wrap : public SimdBlockFilter, public node::ObjectWrap {
public:
static void Init(v8::Local<v8::Object> exports);
simd_block_wrap(const int log_heap_space);
private:
virtual ~simd_block_wrap();
static void Add(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Find(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Persistent<v8::Function> constructor;
};
}
#endif /* simd_block_wrap_hpp */
这是binding.gyp的代码:
{
"targets": [{
"target_name": "addon",
"sources": [
"addon.cpp",
"SimdBlockFilter.h",
"simd_block_wrap.cpp",
"simd_block_wrap.h",
"hashutil.cc",
"hashutil.h",
],
"xcode_settings": {
"OTHER_CFLAGS": [ "-ObjC" ],
"OTHER_CPLUSPLUSFLAGS" : ["-std=c++11","-stdlib=libc++", "-v"],
"MACOSX_DEPLOYMENT_TARGET": "10.9",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
},
}]
}
,还有c ++库SimdBlockFilter.h的代码
#pragma once
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <new>
#include <immintrin.h>
#include "hashutil.h"
using uint32_t = ::std::uint32_t;
using uint64_t = ::std::uint64_t;
template<typename HashFamily =
::cuckoofilter::TwoIndependentMultiplyShift>
class SimdBlockFilter {
private:
// The filter is divided up into Buckets:
using Bucket = uint32_t[8];
// log2(number of bytes in a bucket):
static constexpr int LOG_BUCKET_BYTE_SIZE = 5;
static_assert(
(1 << LOG_BUCKET_BYTE_SIZE) == sizeof(Bucket) && sizeof(Bucket) == sizeof(__m256i),
"Bucket sizing has gone awry.");
// log_num_buckets_ is the log (base 2) of the number of buckets in the directory:
const int log_num_buckets_;
// directory_mask_ is (1 << log_num_buckets_) - 1. It is precomputed in the contructor
// for efficiency reasons:
const uint32_t directory_mask_;
Bucket* directory_;
HashFamily hasher_;
public:
// Consumes at most (1 << log_heap_space) bytes on the heap:
explicit SimdBlockFilter(const int log_heap_space);
SimdBlockFilter(SimdBlockFilter&& that)
: log_num_buckets_(that.log_num_buckets_),
directory_mask_(that.directory_mask_),
directory_(that.directory_),
hasher_(that.hasher_) {}
~SimdBlockFilter() noexcept;
void Add(const uint64_t key) noexcept;
bool Find(const uint64_t key) const noexcept;
uint64_t SizeInBytes() const { return sizeof(Bucket) * (1ull << log_num_buckets_); }
private:
// A helper function for Insert()/Find(). Turns a 32-bit hash into a 256-bit Bucket
// with 1 single 1-bit set in each 32-bit lane.
static __m256i MakeMask(const uint32_t hash) noexcept;
SimdBlockFilter(const SimdBlockFilter&) = delete;
void operator=(const SimdBlockFilter&) = delete;
};
谢谢。
答案 0 :(得分:0)
这可能意味着您的包含路径未正确设置。尝试将'include_dirs': ["include/path/for/SimdBlockFilter"]
添加到您的binding.gyp中。
您的源文件中还应该包含#include "v8.h"
。