我在扩展rocksdb :: Comparator的当前类中遇到了一些链接问题。
“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中的类:
&LT; rocksdb / comparator.h&gt;
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 reprence to“typeinfo for rocksdb :: Comparator”
collect2:错误:ld返回1退出状态
即使我认为我如何扩展课程也存在问题(但从一开始我就不知道,因为我试图按照comparator_db_test.cc
中提供的示例进行操作,因此链接是自动提供的通过使用详细标记,CMake as显示如下:
/ 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
Comparator类是虚拟的并在标头中提供,因此它不应该是链接问题。我甚至尝试在编译.cpp文件时设置-frtti标志,甚至将类声明移动到.h本身,但什么都没发生。我一直在阅读StackOverflow上的所有答案,但我找不到解决方案。