2017-05-04 48 views
0

我試圖在MacOS上安裝boost,以便與開源軟件一起使用。首先,我想跟隨這個例子。Boosts示例Unix入門手冊不起作用

我首先使用Homebrew安裝boost(brew install boost)。

然後我嘗試編譯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; 
    } 
} 

使用這個命令: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

我也得到一個很長的錯誤消息:

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 

我已經花了2天時間了,不能爲我的生活弄清楚我做錯了什麼。有沒有人看到任何明顯/有任何建議?如果有人想嘗試用boost進行編譯,可以找到我想要安裝的開源軟件here

這裏是調用的結果「G ++」:/opt/local/bin/g++

而且我$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 

回答

0

你不應該需要所有這些額外的路徑進入自制目錄,或者明確的聯繫libboost_regex 。一個。

安裝的Xcode 8.3.2以下爲我工作在MacOS塞拉利昂10.12.4:

g++ -Wall example.cpp -lboost_regex 
+0

感謝您的建議。不幸的是,我還安裝了Xcode 8.3.2,並且您寫的命令返回的錯誤與我在我的問題中發佈的錯誤相同。 –

+0

你可以將PATH變量的內容添加到問題中,還可以添加'哪個g ++'的結果? –

+0

好的,我已添加它。 –