Clang提升了怪异性

时间:2012-07-08 22:19:20

标签: macos boost clang macports

我正在做宠物项目并使用clang ++(特别是MacPorts clang 3.1)。所以我决定切换到libc ++(使用std :: array等),但我使用的是boost(特别是asio和regex),所以我不得不使用libc ++重新编译boost。我删除了安装在macports中的boost并从源代码构建了boost,现在安装在/ usr / local / include和/ usr / local / lib中。从那以后,我无法编译。以下是我遇到的奇怪之处:<​​/ p>

执行时:

clang++ -g  -std=c++11 -stdlib=libc++ -c main.cpp

我得到一个奇怪的编译错误,与移动构造函数有关(这个错误还有更多,但正如你可以看到它来自boost):

/usr/include/c++/v1/string:1952:10: error: overload resolution selected implicitly-deleted copy assignment operator
__r_ = _STD::move(__str.__r_);
     ^
/usr/include/c++/v1/string:1942:9: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
    __move_assign(__str, true_type());
    ^
/usr/include/c++/v1/string:1961:5: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
__move_assign(__str, integral_constant<bool,
^
/usr/local/include/boost/regex/v4/perl_matcher.hpp:207:16: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=' requested here
        s1 = traits_inst.transform(a, a + 1);

然而,当我执行时(请注意“-I”,它必须在那个确切的位置):

clang++ -I -std=c++11 -stdlib=libc++ -g -c main.cpp

这个编译(但后来链接失败)。为什么是这样?什么 - 我没有路径?必须-stdlib =以-I?

开头

现在有趣的部分:

尽管现在一切都在编译,但它不会链接。执行时:

clang++ main.o FTPClient.o FTPConnection.o -lboost_system -lboost_regex -std=c++11 -stdlib=libc++  -g  -o cli

我收到消息:

Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
  boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in libboost_regex.a(instances.o)
  boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname_imp(char const*, char const*) const in libboost_regex.a(instances.o)
  boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long) in libboost_regex.a(instances.o)
  boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname(char const*, char const*) const in libboost_regex.a(instances.o)
  ld: symbol(s) not found for architecture x86_64

现在我想也许我错过了一些-lboost标志,但我不确定它是什么。这可能是什么原因?

非常感谢!

编辑:在查看安装boost的日志时,我注意到了这一点:

..failed clang-darwin.link.dll /usr/local/lib/libboost_filesystem.dylib...
clang-darwin.link.dll /usr/local/lib/libboost_regex.dylib
Undefined symbols for architecture x86_64:
  "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
  boost::c_regex_traits<char>::transform(char const*, char const*) in c_regex_traits.o
  boost::c_regex_traits<char>::lookup_classname(char const*, char const*) in c_regex_traits.o
  boost::c_regex_traits<char>::lookup_collatename(char const*, char const*) in c_regex_traits.o
  boost::re_detail::RegExData::update() in cregex.o
  boost::RegEx::What(int) const in cregex.o
  boost::re_detail::pred2::operator()(boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > const&) in cregex.o
  boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in instances.o
  ...
  "__ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initIPKwEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
  boost::c_regex_traits<wchar_t>::transform(wchar_t const*, wchar_t const*) in wc_regex_traits.o


  boost::c_regex_traits<wchar_t>::lookup_classname(wchar_t const*, wchar_t const*) in wc_regex_traits.o
  boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_collatename(wchar_t const*, wchar_t const*) const in winstances.o
  boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_classname_imp(wchar_t const*, wchar_t const*) const in winstances.o
  boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_classname(wchar_t const*, wchar_t const*) const in winstances.o
ld: symbol(s) not found for architecture x86_64  
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是否意味着强制正则表达式可能与-libc ++不兼容?

编辑2:我尝试使用std :: regex,但我明白了:

Undefined symbols for architecture x86_64:
   "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
  std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in main.o
  unsigned int std::__1::regex_traits<char>::__lookup_classname<char const*>(char const*, char const*, bool, char) const in main.o
 ld: symbol(s) not found for architecture x86_64

1 个答案:

答案 0 :(得分:2)

一个有用但不尽如人意的答案:libc ++包含std :: regex,你可以用它代替boost :: regex。