0

I'm using an external library that has a class bplus_tree that is defined in a namespace bpt. The class declaration is below

// bpt.h
class bplus_tree {
public:
    bplus_tree(const char *path, bool force_empty = false);

// bpt.cc
bplus_tree::bplus_tree(const char *p, bool force_empty)
    : fp(NULL), fp_level(0)
{ code here }

I'm referencing it from another file main.cpp that has the following code

// main.cpp

#include "BPlusTree/bpt.h" // This is the correct path to the bpt.h file

bplus_tree tree("", false); // Error here

When I try and compile this with g++ main.cpp -o main -std=c++11, I get the following error.

error: unknown type name 'bplus_tree'; did you mean 'bpt::bplus_tree'?

When I change bplus_tree to bpt::bplus_tree, however, I get the new error:

Undefined symbols for architecture x86_64:
  "bpt::bplus_tree::bplus_tree(char const*, bool)", referenced from:
      _main in main_2-c3bbcc.o
ld: symbol(s) not found for architecture x86_64

I've tried a lot of different combinations for a couple hours now, and I'm honestly not sure what's going on. Is it just something obvious that I am missing or what else am I not getting?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Eric Feng
  • 1
  • 1
  • You're not passing `bpt.cc` to the compiler when you're linking the executable (hence "undefined symbol" - the linker can't find the definition for `bpt::bplus_tree`) Try running `g++ main.cpp bpt.cc -o main -std=c++11` – Brian61354270 Apr 18 '20 at 20:35
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Brian61354270 Apr 18 '20 at 20:39
  • Yes! Thanks so much for your help! – Eric Feng Apr 18 '20 at 20:40

0 Answers0