mercredi 29 juin 2016

Compiling simple C++ program with dependencies [duplicate]


I'm new to C++ (coming from the Java world), and am writing a simple toy program to learn the syntax. I've written a simple database class (in db_database.h and db_database.cpp) and a main.cpp file that interacts with the database class.

Upon compiling using the command g++ main.cpp -o main, I get the following error:

Undefined symbols for architecture x86_64:
  "db::Database::print_contents()", referenced from:
      _main in main-5f85bd.o
  "db::Database::add_entry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main-5f85bd.o
  "db::Database::Database()", referenced from:
  _main in main-5f85bd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see     invocation)

I'm assuming that I'm simply not addressing the fact that main.cpp includes db_database.h.

How do I get this to compile?


Aucun commentaire:

Enregistrer un commentaire