dimanche 27 septembre 2020

Undefined symbols for architecture x86_64: vtable

I'm doing a c++ project where I implemented my own Hash Table. Then I try to use this hash table and when intializing this, I got error at build stage from linker.

Undefined symbols for architecture x86_64:
  "bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator>::Insert(bustub::Transaction*, unsigned long const&, bustub::TmpTuple const&)", referenced from:
      bustub::HashJoinExecutor::Init() in hash_join_executor.cpp.o
      vtable for bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator> in hash_join_executor.cpp.o
  "bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator>::Remove(bustub::Transaction*, unsigned long const&, bustub::TmpTuple const&)", referenced from:
      vtable for bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator> in hash_join_executor.cpp.o
  "bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator>::GetValue(bustub::Transaction*, unsigned long const&, std::__1::vector<bustub::TmpTuple, std::__1::allocator<bustub::TmpTuple> >*)", referenced from:
      bustub::HashJoinExecutor::Next(bustub::Tuple*) in hash_join_executor.cpp.o
      vtable for bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator> in hash_join_executor.cpp.o
  "bustub::LinearProbeHashTable<unsigned long, bustub::TmpTuple, bustub::HashComparator>::LinearProbeHashTable(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bustub::BufferPoolManager*, bustub::HashComparator const&, unsigned long, bustub::HashFunction<unsigned long>)", referenced from:
      bustub::HashJoinExecutor::HashJoinExecutor(bustub::ExecutorContext*, bustub::HashJoinPlanNode const*, std::__1::unique_ptr<bustub::AbstractExecutor, std::__1::default_delete<bustub::AbstractExecutor> >&&, std::__1::unique_ptr<bustub::AbstractExecutor, std::__1::default_delete<bustub::AbstractExecutor> >&&) in hash_join_executor.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libbustub_shared.dylib] Error 1
make[1]: *** [src/CMakeFiles/bustub_shared.dir/all] Error 2

My code to specify hash table type:

   using HashJoinKeyType = hash_t;
   using HashJoinValType = TmpTuple;
   using HT = LinearProbeHashTable<HashJoinKeyType, HashJoinValType, HashComparator>;

Value type is a class:

class TmpTuple {
 public:
  TmpTuple(page_id_t page_id, size_t offset) : page_id_(page_id), offset_(offset) {}

  inline bool operator==(const TmpTuple &rhs) const { return page_id_ == rhs.page_id_ && offset_ == rhs.offset_; }

  page_id_t GetPageId() const { return page_id_; }
  size_t GetOffset() const { return offset_; }

 private:
  page_id_t page_id_;
  size_t offset_;
};

There is my constructor for hash table

    template<typename KeyType, typename ValueType, typename KeyComparator>
    class LinearProbeHashTable : public HashTable<KeyType, ValueType, KeyComparator> {
    public:
        /**
         * Creates a new LinearProbeHashTable
         *
         * @param buffer_pool_manager buffer pool manager to be used
         * @param comparator comparator for keys
         * @param num_buckets initial number of buckets contained by this hash table
         * @param hash_fn the hash function
         */
        explicit LinearProbeHashTable(const std::string &name, BufferPoolManager *buffer_pool_manager,
                                      const KeyComparator &comparator, size_t num_buckets,
                                      HashFunction<KeyType> hash_fn);

I've been working on this for 3hrs and have no idea what to do, could anyone give me some insights/advice?

Aucun commentaire:

Enregistrer un commentaire