来自Boosts的示例入门手册for Unix无法正常工作

时间:2017-05-04 20:23:25

标签: c++ regex boost

我正在尝试在MacOS上安装boost以与开源软件一起使用。首先,我想跟随这个例子。

我首先使用Homebrew来安装boost(c++ -I /usr/local/Cellar/boost/1.64.0_1/ example.cpp -o example /usr/local/Cellar/boost/1.64.0_1/lib/libboost_regex.a)。

然后我尝试编译example.cpp代码

Undefined symbols for architecture x86_64:
  "boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, 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)", referenced from:
      boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >) in ccCPUnqq.o

使用此命令:"std::__1::locale::operator=(std::__1::locale const&)", referenced from: boost::re_detail_106400::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in libboost_regex.a(instances.o) "std::__1::collate<char>::id", referenced from: boost::re_detail_106400::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in libboost_regex.a(instances.o) "std::__1::ios_base::init(void*)", referenced from: boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o) "std::__1::ios_base::clear(unsigned int)", referenced from: boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o) "std::__1::messages<char>::id", referenced from: boost::re_detail_106400::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in libboost_regex.a(instances.o) "std::__1::numpunct<char>::id", referenced from: boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o) "std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()", referenced from: boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o) "typeinfo for std::__1::basic_streambuf<char, std::__1::char_traits<char> >", referenced from: typeinfo for boost::re_detail_106400::parser_buf<char, std::__1::char_traits<char> > in libboost_regex.a(instances.o) "vtable for std::__1::basic_istream<char, std::__1::char_traits<char> >", referenced from: boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o) NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status

我收到一条很长的错误信息:

/opt/local/bin/g++

... OMMITTED ...

$PATH

我花了两天时间在这上面并且不能为我的生活弄清楚我做错了什么。有没有人看到任何明显/有任何建议?如果有人想尝试用boost编译它,可以找到我试图安装的开源软件this question

以下是调用&#39; g ++&#39;:/usr/local/gcc/bin:/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/net/dnscrypt-proxy/Portfile:/Applications:/Applications:/Applications/sratoolkit.2.8.0-mac64/bin:/Applications/STAR/bin/MacOSX_x86_64:/Users/johngiorgi/.local/bin:/Users/johngiorgi/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/Applications/ncbi-blast-2.4.0+/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/var/rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Cellar/boost/1.64.0_1/include:/usr/local/Cellar/boost/1.64.0_1/include/boost/tr1 :/opt/X11/bin:/usr/local/go/bin:/Library/TeX/texbin

的结果

我的https://api.intrinio.com/financials/standardized?identifier=YUM&statement=income_statement&fiscal_period=Q2&fiscal_year=2015

https://api.intrinio.com/companies?latest_filing_date=2017-03-06

1 个答案:

答案 0 :(得分:0)

您不应该需要Homebrew目录中的所有其他路径,或者libboost_regex.a的显式链接。

以下是在安装了Xcode 8.3.2的macOS Sierra 10.12.4上为我工作的:

g++ -Wall example.cpp -lboost_regex