I have a header file defined as db.hpp
as follows:
#ifndef PMT_DB_H
#define PMT_DB_H
#include <leveldb/db.h>
#include <vector>
#include <map>
class DBConnection {
private:
std::string db_file_;
leveldb:: DB* db_;
leveldb::Status status_;
std::map<std::string, std::string> uncommitted_;
public:
DBConnection(const std::string &db_file);
// Other functions
};
#endif
My db.cpp
class is as follows:
#include "db.hpp"
#include <leveldb/write_batch.h>
#include <string>
DBConnection::DBConnection(const std::string &db_file) {
db_file_ = db_file;
leveldb::Options options;
options.create_if_missing = true;
status_ = leveldb::DB::Open(options, db_file, &db_);
}
// other functions
Here is how my main file patricia-merkle-trie.cpp
looks like:
#include <iostream>
#include "core/db.hpp"
void say_hello(){
std::cout << "Hello, from patricia-merkle-trie!\n";
}
int main() {
say_hello();
const std::string db_path_ {"/tmp/testdb"};
DBConnection db_connection = DBConnection(db_path_);
// Rest of the code
}
I tried to compile this with the following command:
g++ patricia-merkle-trie.cpp -o pmt_test -pthread -L/usr/local/lib -lleveldb -std=c++14
It gives me error as follows:
/tmp/ccH2lHTf.o: In function `main':
patricia-merkle-trie.cpp:(.text+0x87): undefined reference to `DBConnection::DBConnection(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
I know this is a linker error, but not getting why this error is coming. I have defined the content string as a parameter to the constructor, the definition and declaration of the constructor are exactly the same. Then why does it show the call to the constructor as two parametrized?