架构x86_64的未定义符号:leveldb :: Comparator的typeinfo“

时间:2019-08-27 08:51:04

标签: c++ leveldb

我正在尝试在Mac上将以下代码与leveldb进行编译和链接:

#include "leveldb/comparator.h"

class KeyComparator: public leveldb::Comparator {
public:
        virtual ~KeyComparator() {}

        virtual int Compare(const leveldb::Slice& a, const leveldb::Slice& b) const  {
                return 0;
        }

        virtual const char* Name() const  {
                return "test";
        }

        virtual void FindShortestSeparator(std::string* start, const leveldb::Slice& limit) const  {
        }

        virtual void FindShortSuccessor(std::string* key) const  {
        }
};
int main() {
        KeyComparator comp;
        return 0;
}
git clone https://github.com/google/leveldb.git
cd leveldb/
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
g++  -I leveldb/include/ -L leveldb/build/ -l leveldb test.cpp

但是出现以下错误:

Undefined symbols for architecture x86_64:
  "typeinfo for leveldb::Comparator", referenced from:
      typeinfo for KeyComparator in test-d20952.o
ld: symbol(s) not found for architecture x86_64

有人知道哪里错了吗?谢谢。

0 个答案:

没有答案