我有一些鏈接問題與當前類擴展rocksdb :: Comparator。爲RocksDB實現一個比較器
「NumericKeyComparator.cpp」
#include <rocksdb/db.h>
#include <rocksdb/comparator.h>
#include "../../structure/structure.h"
#include "../../NumberToString.h"
#include <map>
#include <string>
#include "rocksdb/db.h"
#include "rocksdb/env.h"
namespace rocksdb {
namespace {
class NumericKeyComparator : public Comparator {
public:
~NumericKeyComparator() {}
NumericKeyComparator() {}
// Three-way comparison function:
// if a < b: negative result
// if a > b: positive result
// else: zero result
virtual int Compare(const Slice &a, const Slice &b) const override {
LONG_NUMERIC x, y;
x = StringToNumber<LONG_NUMERIC>(std::string(a.data()));
y = StringToNumber<LONG_NUMERIC>(std::string(b.data()));
if (x == y) return 0;
if (x < y) return -1;
return 1;
};
virtual bool Equal(const Slice &a, const Slice &b) const override {
return StringToNumber<LONG_NUMERIC>(std::string(a.data())) ==
StringToNumber<LONG_NUMERIC>(std::string(b.data()));
}
// Ignore the following methods for now:
virtual const char *Name() const { return "NumericKeyComparator"; };
virtual void FindShortestSeparator(std::string *, const Slice &) const override {};
virtual void FindShortSuccessor(std::string *) const {};
};
}
}
const rocksdb::Comparator* nkcmp() {
static rocksdb::NumericKeyComparator cmp;
return &cmp;
}
特別地,原始類(由h文件提供)是以下,相當於性LevelDB類:
< rocksdb /comparator.h>
class Comparator {
public:
virtual ~Comparator();
virtual int Compare(const Slice& a, const Slice& b) const = 0;
virtual bool Equal(const Slice& a, const Slice& b) const {
return Compare(a, b) == 0;
}
virtual const char* Name() const = 0;
virtual void FindShortestSeparator(
std::string* start,
const Slice& limit) const = 0;
virtual void FindShortSuccessor(std::string* key) const = 0;
virtual const Comparator* GetRootComparator() const { return this; }
};
在連接階段本身的可執行文件,涉及到.o文件將以下引發錯誤:
NumericKeyComparator.cpp.o:(.data.rel.ro+0x10): undefined rederence to "typeinfo for rocksdb::Comparator"
collect2: error: ld returned 1 exit status
即使我覺得這是我如何擴展的類問題(但誠懇地說,我不知道,因爲我已經試過跟隨comparator_db_test.cc
提供的示例中,連接是自動由CMake的提供爲,通過使用詳細標誌,顯露是以下內容:
/usr/bin/c++ -fopenmp -lpthread -lrt -lsnappy -lz -lbz2 -llz4 -lzstd -lnuma -g CMakeFiles/.dir//main.cpp.o ... CMakeFiles/.dir//lib/serializer/rocksdb/comparators/NumericKeyComparator.cpp.o -o -L/usr/lib/x86_64-linux-gnu/libsnappy.so -L/usr/lib/x86_64-linux-gnu/liblz4.so -L/usr/local/lib/librocksdb.a -Wl,-rpath,/usr/lib/x86_64-linux-gnu/libsnappy.so:/usr/lib/x86_64-linux-gnu/liblz4.so:/usr/local/lib/librocksdb.a ../_tests/lib/googletest/googlemock/gtest/libgtest.a /usr/local/lib/libstxxl_debug.a -lpthread /usr/lib/x86_64-linux-gnu/libboost_graph.a /usr/lib/x86_64-linux-gnu/libboost_serialization.a /usr/lib/x86_64-linux-gnu/libboost_system.a /usr/lib/x86_64-linux-gnu/libboost_filesystem.a /usr/local/BerkeleyDB.6.2/lib/libdb-6.2.a -lrocksdb -lpthread -lm -lsnappy -llz4 -lz -lbz2 -lzstd
比較器類是虛擬和報頭內提供的,所以它不應該是一個鏈接問題。我甚至嘗試在編譯.cpp文件時設置-frtti標誌,甚至將類聲明移到.h本身,但什麼都沒有發生。我一直在閱讀StackOverflow的所有答案,但我沒有找到解決方案。