在Ubuntu中包括MongoDB C 驱动程序的错误

Error in including MongoDB C++ driver in Ubuntu

本文关键字:驱动程序 错误 MongoDB Ubuntu 包括      更新时间:2023-10-16

我一直在尝试将C 连接到MongoDB,但是它在许多层面上都会出现错误,现在我陷入了编译简单的代码。我遵循了本教程。我尝试使用下面的命令来编译教程中给出的代码。

g++ tutorial.cpp -Iinstall/include -Linstall/lib -pthread -lmongoclient -lboost_thread -lboost_filesystem -lboost_program_options -lboost_system -o tutorial

但它在控制台上打印了一个巨大的日志,并带有错误。最终部分输出在下面。

 nce to `boost::re_detail::put_mem_block(void*)'
install/lib/libmongoclient.a(dbclient.o): In function `perl_matcher':
/usr/include/boost/regex/v4/perl_matcher.hpp:374: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
install/lib/libmongoclient.a(dbclient.o): In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_match()':
/usr/include/boost/regex/v4/perl_matcher_non_recursive.hpp:973: undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > > const&)'
collect2: error: ld returned 1 exit status

有人可以解释如何纠正此问题吗?

我通过在构建路径中添加" lboost_regex"来纠正此错误。我在此博客文章中纠正了官方教程中的所有错误。