0

我正在尝试使用正则表达式构建一个非常简单的 boost 示例,只是为了尝试在 XCode 项目中使用 boost,但我遇到了一些奇怪的问题。

首先,我下载了 boost 1.53.0,然后使用以下命令引导并构建它:

./bootstrap.sh --with-libraries=regex

./b2 install

然后我做了一个非常简单的正则表达式示例程序:

#include <iostream>
#include <boost/regex.hpp>

int main(int argc, const char * argv[])
{

std::string text(" 192.168.0.1 abc 10.0.0.255 10.5.1 1.2.3.4a 5.4.3.2 ");
const char* pattern =
"\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
"\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
"\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
"\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
boost::regex ip_regex(pattern);

boost::sregex_iterator it(text.begin(), text.end(), ip_regex);
boost::sregex_iterator end;
for (; it != end; ++it) {
    std::cout << it->str() << "\n";
    // v.push_back(it->str()); or something similar
}
return 0;
}

我将我构建的静态库(boost_regex.a)添加到“Link Binary With Libraries”下的项目设置 Build Phases 中,这也隐式更新了构建设置“Library Search Paths”以指向 .a 文件所在的库.

当我尝试构建时,我现在收到一堆与标准 C++ 库相关的链接器错误。这是一个片段:

"__gnu_debug::_Safe_sequence_base::_M_detach_all()", referenced from:
      __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base() in libboost_regex.a(cregex.o)
      __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base() in libboost_regex.a(instances.o)
      __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base() in libboost_regex.a(posix_api.o)
      __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base() in libboost_regex.a(wide_posix_api.o)
      __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base() in libboost_regex.a(winstances.o)
  "__gnu_debug::_Error_formatter::_M_message(__gnu_debug::_Debug_msg_id) const", referenced from:
      boost::re_detail::character_pointer_range<char> const* std::lower_bound<boost::re_detail::character_pointer_range<char> const*, boost::re_detail::character_pointer_range<char> >(boost::re_detail::character_pointer_range<char> const*, boost::re_detail::character_pointer_range<char> const*, boost::re_detail::character_pointer_range<char> const&) in libboost_regex.a(c_regex_traits.o)
      bool std::equal<char const*, char const*>(char const*, char const*, char const*) in libboost_regex.a(c_regex_traits.o)
      std::lexicographical_compare(char const*, char const*, char const*, char const*) in libboost_regex.a(c_regex_traits.o)
      bool std::lexicographical_compare<signed char const*, signed char const*>(signed char const*, signed char const*, signed char const*, signed char const*) in libboost_regex.a(c_regex_traits.o)
      std::string::replace(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*) in libboost_regex.a(c_regex_traits.o)
      std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > >::erase(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > >, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > >) in libboost_regex.a(cregex.o)
      std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > >::erase(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > >, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > >) in libboost_regex.a(cregex.o)
      ...
  "__gnu_debug::_Error_formatter::_M_error() const", referenced from:
      boost::re_detail::character_pointer_range<char> const* std::lower_bound<boost::re_detail::character_pointer_range<char> const*, boost::re_detail::character_pointer_range<char> >(boost::re_detail::character_pointer_range<char> const*, boost::re_detail::character_pointer_range<char> const*, boost::re_detail::character_pointer_range<char> const&) in libboost_regex.a(c_regex_traits.o)
      bool std::equal<char const*, char const*>(char const*, char const*, char const*) in libboost_regex.a(c_regex_traits.o)
      std::lexicographical_compare(char const*, char const*, char const*, char const*) in libboost_regex.a(c_regex_traits.o)
      bool std::lexicographical_compare<signed char const*, signed char const*>(signed char const*, signed char const*, signed char const*, signed char const*) in libboost_regex.a(c_regex_traits.o)
      std::string::replace(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*) in libboost_regex.a(c_regex_traits.o)
      std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > >::erase(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > >, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > >) in libboost_regex.a(cregex.o)
      std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > >::erase(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > >, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > >) in libboost_regex.a(cregex.o)
      ...
  "__gnu_debug::_Safe_iterator_base::_M_singular() const", referenced from:
      __gnu_debug::_Safe_iterator<std::__norm::_List_iterator<std::string>, std::__debug::list<std::string, std::allocator<std::string> > >::operator=(__gnu_debug::_Safe_iterator<std::__norm::_List_iterator<std::string>, std::__debug::list<std::string, std::allocator<std::string> > > const&) in libboost_regex.a(cregex.o)
      bool __gnu_debug::operator!=<std::__norm::_List_iterator<std::string>, std::__debug::list<std::string, std::allocator<std::string> > >(__gnu_debug::_Safe_iterator<std::__norm::_List_iterator<std::string>, std::__debug::list<std::string, std::allocator<std::string> > > const&, __gnu_debug::_Safe_iterator<std::__norm::_List_iterator<std::string>, std::__debug::list<std::string, std::allocator<std::string> > > const&) in libboost_regex.a(cregex.o)
      bool __gnu_debug::operator==<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > >(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > > const&, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, long> >, std::__debug::map<int, long, std::less<int>, std::allocator<std::pair<int const, long> > > > const&) in libboost_regex.a(cregex.o)
      bool __gnu_debug::operator==<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > >(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > > const&, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > > const&) in libboost_regex.a(cregex.o)
      bool __gnu_debug::operator!=<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > >(__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > > const&, __gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<int const, std::string> >, std::__debug::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > > > const&) in libboost_regex.a(cregex.o)

有谁知道可能是什么原因造成的?我想不出任何更简单的测试用例......

4

1 回答 1

0

不确定这是否有帮助,但是当我几年前尝试在 Xcode 中使用 Boost 时,我发现我无法使用预构建的库。相反,我不得不将所有文件添加到 Xcode 项目中。原因可能是 boost 自己的安装脚本使用 Xcode 项目不匹配的选项构建库。但是如果你让 Xcode 来构建它,你就很好了。

于 2013-08-19T15:02:37.477 回答