2

C++ のサンプル コードをコンパイルすると、次の情報が得られました。

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

何が問題なのかわかりません。助けてください!

更新:今私は使用します:

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

それでもエラーが発生します:

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
4

2 に答える 2

4

BerkeleyDB c++ ライブラリにリンクする必要があります。

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) ディレクティブに基づくバージョンがあると仮定しています。)

編集:したがって、ディストリビューション (excxx_example_database_read.cpp) に含まれるサンプルの 1 つを手動でコンパイルしようとしているようです...それは複数の .cpp ファイルです。MyDB オブジェクトは BerkeleyDB API の一部ではなく、BerkeleyDB API からサブクラス化する方法の例です。

cdあなたがBerkeleyDBのソースコードを持っている場所に移動してからcd build_unix. そこに着いたら、make excxx_example_database_read

于 2010-04-16T21:34:31.613 に答える
1

これらはリンカー エラーです。これは、このアプリケーションのビルドに必要な 1 つ以上のライブラリにリンクしていないことを意味します。

ライブラリのドキュメントでは、ライブラリを使用してアプリケーションを構築する方法を説明する必要があります。一般に、ライブラリをコンパイラ コマンド ラインに追加する必要があります。

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

ライブラリ検索パスにあるlibsomething.aにリンクします。ただし、どれをリンクするかを知るには、ドキュメントを読む必要があります。

于 2010-04-13T09:01:43.120 に答える