如何在C++或Python中使用Berkeley DB?

问题描述 投票:0回答:1

我在ubuntu wsl中,无法运行从Oracle下载的程序。 BDB的版本是18.1.4,我准备运行examples/cxx/getting_started; 我的项目架构正在崩溃:

➜  getting_started tree ./ -L 1
./
├── CMakeLists.txt
├── bin
├── build
├── excxx_example_database_read.cpp
├── include
└── src

错误是:

➜  build cmake ../
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /root/db-18.1.40/examples/cxx/getting_started/build
➜  build make       
[ 33%] Building CXX object CMakeFiles/BDB.dir/src/MyDb.cpp.o
[ 66%] Building CXX object CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o
[100%] Linking CXX executable /root/db-18.1.40/examples/cxx/getting_started/bin/BDB
/usr/bin/ld: CMakeFiles/BDB.dir/src/MyDb.cpp.o: in function `MyDb::MyDb(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)':
/root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:19: undefined reference to `Db::Db(DbEnv*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:25: undefined reference to `Db::set_error_stream(std::ostream*)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:30: undefined reference to `Db::set_flags(unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:33: undefined reference to `Db::open(DbTxn*, char const*, char const*, DBTYPE, unsigned int, int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:19: undefined reference to `Db::~Db()'
/usr/bin/ld: CMakeFiles/BDB.dir/src/MyDb.cpp.o: in function `MyDb::close()':
/root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:57: undefined reference to `Db::close(unsigned int)'
/usr/bin/ld: CMakeFiles/BDB.dir/src/MyDb.cpp.o:(.data.rel.local.DW.ref._ZTI11DbException[DW.ref._ZTI11DbException]+0x0): undefined reference to `typeinfo for DbException'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `main':
/root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:115: undefined reference to `DbException::get_errno() const'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `loadInventoryDB(MyDb&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:185: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:189: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:189: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:185: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:189: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:185: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `loadVendorDB(MyDb&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:230: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:231: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:231: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:230: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:231: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:230: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `MyDb::~MyDb()':
/root/db-18.1.40/examples/cxx/getting_started/./include/MyDb.hpp:26: undefined reference to `Db::~Db()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/BDB.dir/build.make:113: /root/db-18.1.40/examples/cxx/getting_started/bin/BDB] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/BDB.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
➜  build

另外,我也想用python,但是

pip3 install bsddb3
,也失败了。

➜  db-18.1.40 pip3 install bsddb3
Collecting bsddb3
  Using cached https://files.pythonhosted.org/packages/f0/24/92034482656945fc6ceb10551222b43a0ff8d0c87e15839120487820067e/bsddb3-6.2.9.tar.gz
    Complete output from command python setup.py egg_info:
    Can't find a local Berkeley DB installation.
    (suggestion: try the --berkeley-db=/path/to/bsddb option)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-73xvaexa/bsddb3/

如何使用 Berkeley DB?

➜  getting_started tree ./ -L 1
./
├── CMakeLists.txt
├── bin
├── build
├── excxx_example_database_read.cpp
├── include
└── src

错误是:

➜  build cmake ../
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /root/db-18.1.40/examples/cxx/getting_started/build
➜  build make       
[ 33%] Building CXX object CMakeFiles/BDB.dir/src/MyDb.cpp.o
[ 66%] Building CXX object CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o
[100%] Linking CXX executable /root/db-18.1.40/examples/cxx/getting_started/bin/BDB
/usr/bin/ld: CMakeFiles/BDB.dir/src/MyDb.cpp.o: in function `MyDb::MyDb(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)':
/root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:19: undefined reference to `Db::Db(DbEnv*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:25: undefined reference to `Db::set_error_stream(std::ostream*)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:30: undefined reference to `Db::set_flags(unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:33: undefined reference to `Db::open(DbTxn*, char const*, char const*, DBTYPE, unsigned int, int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:19: undefined reference to `Db::~Db()'
/usr/bin/ld: CMakeFiles/BDB.dir/src/MyDb.cpp.o: in function `MyDb::close()':
/root/db-18.1.40/examples/cxx/getting_started/src/MyDb.cpp:57: undefined reference to `Db::close(unsigned int)'
/usr/bin/ld: CMakeFiles/BDB.dir/src/MyDb.cpp.o:(.data.rel.local.DW.ref._ZTI11DbException[DW.ref._ZTI11DbException]+0x0): undefined reference to `typeinfo for DbException'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `main':
/root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:115: undefined reference to `DbException::get_errno() const'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `loadInventoryDB(MyDb&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:185: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:189: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:189: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:185: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:189: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:185: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `loadVendorDB(MyDb&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:230: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:231: undefined reference to `Dbt::Dbt(void*, unsigned int)'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:231: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:230: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:231: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: /root/db-18.1.40/examples/cxx/getting_started/src/excxx_example_database_load.cpp:230: undefined reference to `Dbt::~Dbt()'
/usr/bin/ld: CMakeFiles/BDB.dir/src/excxx_example_database_load.cpp.o: in function `MyDb::~MyDb()':
/root/db-18.1.40/examples/cxx/getting_started/./include/MyDb.hpp:26: undefined reference to `Db::~Db()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/BDB.dir/build.make:113: /root/db-18.1.40/examples/cxx/getting_started/bin/BDB] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/BDB.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
➜  build

另外,我也想用python,但是

pip3 install bsddb3
,也失败了。

➜  db-18.1.40 pip3 install bsddb3
Collecting bsddb3
  Using cached https://files.pythonhosted.org/packages/f0/24/92034482656945fc6ceb10551222b43a0ff8d0c87e15839120487820067e/bsddb3-6.2.9.tar.gz
    Complete output from command python setup.py egg_info:
    Can't find a local Berkeley DB installation.
    (suggestion: try the --berkeley-db=/path/to/bsddb option)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-73xvaexa/bsddb3/
berkeley-db
1个回答
0
投票

在安装bsddb3包之前,您需要安装Berkeley DB库和头文件。打开终端并运行以下命令来安装必要的依赖项:

sudo apt-get install libdb-dev
© www.soinside.com 2019 - 2024. All rights reserved.