macos - Clang 增加了奇怪的东西

标签 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 中。从那时起我就无法编译了。以下是我遇到的奇怪现象:

执行时:

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

这可以编译(但稍后链接失败)。为什么是这样? -I 没有路径会做什么? -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)

这是否意味着 boost 正则表达式可能与 -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

最佳答案

一个有用但不令人满意的答案:libc++ 包含 std::regex,您可以使用它来代替 boost::regex。

关于macos - Clang 增加了奇怪的东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11387188/

相关文章:

c++ - Instruments Call Tree 破坏了 R、C++ 和 Fortran 的混合

macos - ./sysroot.sh : Operation not permitted

C++shared_ptr序列化

c++ - 如何将任何值转换为对象并使用 boost::property_tree json 添加成员

c++ - 编译时允许的最大警告数

macos - MAC OS X : Set external USB camera resolution with AVCaptureSession's sessionPreset doesn't work

c++ - 使用 boost.process 同时读取和写入 child 的 stdio

xcode - 如何在没有 xcode 的情况下生成 dSYM 文件?

c - 为什么 #line 指令没有在 clang 的 false #if 中处理?

java - 将 .jar 转换为 Mac OS X 应用程序