简体   繁体   English

Unix的Boosts入门手册中的示例不起作用

[英]Example from Boosts Getting Started Manual for Unix not working

I am trying to install boost on MacOS for use with an open source piece of software. 我试图在MacOS上安装Boost以便与开源软件一起使用。 First I wanted to follow along with the example. 首先,我想跟着这个例子。

I first use Homebrew to install boost ( brew install boost ). 我首先使用Homebrew安装boost( brew install boost )。

Then I try to compile the example.cpp code 然后我尝试编译example.cpp代码

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

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

Using this command: 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 使用以下命令: 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

And I get a very long error message: 而且我收到很长的错误消息:

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

... OMMITTED ... ...省略...

"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

I have spent 2 days on this and cannot for the life of me figure out what I am doing wrong. 我已经花了2天的时间,无法终生了解自己在做什么错。 Does anyone see anything obvious / have any suggestions? 有人看到明显的东西/有什么建议吗? The open source software I am trying to install can be found here if anyone wants to try compiling it with boost. 如果有人想尝试使用boost进行编译,可以在这里找到我要安装的开源软件。

Here is the result of calling 'g++': /opt/local/bin/g++ 这是调用“ g ++”的结果: /opt/local/bin/g++

And my $PATH : 而我的$PATH

/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

You shouldn't need all those additional paths into the Homebrew directories, or the explicit link to libboost_regex.a. 您不需要进入Homebrew目录的所有其他路径,也不需要指向libboost_regex.a的显式链接。

The following worked for me on macOS Sierra 10.12.4 with Xcode 8.3.2 installed: 以下在安装了Xcode 8.3.2的macOS Sierra 10.12.4上为我工作:

g++ -Wall example.cpp -lboost_regex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM