nodejs的c ++插件中的预期类名
Posted
技术标签:
【中文标题】nodejs的c ++插件中的预期类名【英文标题】:expected class name in c++ addon for nodejs 【发布时间】:2018-08-03 08:04:37 【问题描述】:我正在为 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",
,
]
还有 SimdBlockFilter.h 的代码,它是 c++ 库
#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;
;
提前致谢。
【问题讨论】:
您应该在帖子本身中包含错误消息的文本,以便其他人可以找到它,并且如果图像被删除,问题仍然相关。 【参考方案1】:这可能意味着您的包含路径设置不正确。尝试将 'include_dirs': ["include/path/for/SimdBlockFilter"]
添加到您的 binding.gyp。
您的源文件中还应该有#include "v8.h"
。
【讨论】:
以上是关于nodejs的c ++插件中的预期类名的主要内容,如果未能解决你的问题,请参考以下文章