nodejs的c++插件中应有的类名

expected class name in c++ addon for nodejs

本文关键字:c++ 插件 nodejs      更新时间:2023-10-16

我正在为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单独构建它。但总有一个错误:错误

然而,我确实在课堂上加入了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 */

这是绑定的代码。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;
};

提前谢谢。

这可能意味着您的包含路径设置不正确。尝试将'include_dirs': ["include/path/for/SimdBlockFilter"]添加到binding.gyp.

您的源文件中也应该有#include "v8.h"