我正在尝试使用正则表达式构建一个非常简单的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)
有谁知道可能导致这种情况的原因是什么?我想不出更简单的测试用例......
答案 0 :(得分:0)
不确定这是否有帮助,但几年前我在Xcode中尝试使用Boost时,发现我无法使用预建的库。相反,我必须将所有文件添加到Xcode项目中。原因可能是boost自己的安装脚本使用Xcode项目不匹配的选项构建libs。但是,如果你让Xcode全部构建,那就很好。