tags:

views:

152

answers:

2

When I compiled the sample codes of C++, I got following info:

c++ excxx_example_database_read.cpp -o dbApp -I /usr/local/BerkeleyDB.5.0/include/
Undefined symbols:
  "Dbt::Dbt(void*, unsigned int)", referenced from:
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
  "Dbc::get(Dbt*, Dbt*, unsigned int)", referenced from:
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
  "Dbc::close()", referenced from:
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
  "Dbt::~Dbt()", referenced from:
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
  "Db::~Db()", referenced from:
      MyDb::~MyDb() in ccnaWItX.o
      MyDb::~MyDb() in ccnaWItX.o
  "typeinfo for DbException", referenced from:
      GCC_except_table3 in ccnaWItX.o
      GCC_except_table4 in ccnaWItX.o
      GCC_except_table5 in ccnaWItX.o
      GCC_except_table6 in ccnaWItX.o
      __ZTI11DbException$non_lazy_ptr in ccnaWItX.o
  "DbException::~DbException()", referenced from:
      __ZN11DbExceptionD1Ev$non_lazy_ptr in ccnaWItX.o
  "MyDb::close()", referenced from:
      MyDb::~MyDb() in ccnaWItX.o
  "MyDb::MyDb(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)", referenced from:
      _main in ccnaWItX.o
      _main in ccnaWItX.o
      _main in ccnaWItX.o
  "Dbt::Dbt()", referenced from:
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
  "DbException::get_errno() const", referenced from:
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
      _main in ccnaWItX.o
  "DbException::DbException(DbException const&)", referenced from:
      show_vendor(MyDb&, char const*)in ccnaWItX.o
      show_all_records(MyDb&, MyDb&) in ccnaWItX.o
      show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I have no idea what is the problem. Please help!

Update: Now I use :

getting_started baxxu$ c++ excxx_example_database_r
ead.cpp -o dbApp -I /usr/local/BerkeleyDB.5.0/include/ -L/usr/local/
BerkeleyDB.5.0/lib -ldb_cxx-5.0

still get error:

Undefined symbols:
  "MyDb::close()", referenced from:
      MyDb::~MyDb() in ccYCyhIg.o
  "MyDb::MyDb(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)", referenced from:
      _main in ccYCyhIg.o
      _main in ccYCyhIg.o
      _main in ccYCyhIg.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
+1  A: 

These are linker errors - they mean you haven't linked in one or more of the libraries you need to build this application.

The documentation for the library should explain how to build applications using it. In general, you need to add the library to the compiler command line:

c++ excxx_example_database_read.cpp -o dbApp -I /usr/local/BerkeleyDB.5.0/include/  -lsomething

would link in libsomething.a, found on the library search path. But to know which one to link, you must read the docs.

anon
Hi Neil, any tips about how to fix the broken links? I am not familiar with this especially on Mac.:X
Brian
Hey Neil, I spent some time figuring out how to add library to search path, but didn't find any useful information. do you have any tip on setting this on Max Os?
Brian
@Brian you specify additions to the search path with the -L flag, in much the same way you specify the include path with -I. You can also simply put the full path and file name of the library on the compiler command line. For more info on g++, see http://gcc.gnu.org/onlinedocs/
anon
+1  A: 

You need to link to the BerkeleyDB c++ library.

c++ excxx_example_database_read.cpp -o dbApp -I /usr/local/BerkeleyDB.5.0/include/ -L/usr/local/BerkeleyDB.5.0/lib -ldb_cxx-5.0

(I'm assuming that's where you have the library installed and the version based on the include (-I) directive.)

EDIT: So, it appears you're trying to compile one of the examples included in the distribution (excxx_example_database_read.cpp) by hand ... it's more than a single .cpp file. The MyDB object is not part of the BerkeleyDB API but rather an example of how to subclass from it.

cd to where you have the BerkeleyDB source code, then cd build_unix . Once there, do make excxx_example_database_read

Brian Roach
@Brian, after I apply your command, there is still 1 error, see the codes above
Brian