clang-libc++错误:重载解析选择了隐式删除的复制赋值运算符

clang libc++ error: overload resolution selected implicitly-deleted copy assignment operator

本文关键字:删除 赋值运算符 复制 选择 错误 重载 clang-libc++      更新时间:2023-10-16

我无法使用clang 3.1编译C++11项目。编译器的命令是:

clang++-mp-3.1 -c -std=c++11 -stdlib=libc++ -Wall -g -Iinclude -I/usr/local/include -I/opt/local/include -I/usr/local/include/mongo -o world.o world.cpp

由于我包含了"-stdlib=libc++"指令,所以我得到的错误是:

In file included from world.cpp:1:
/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/include/c++/v1/utility:200:24: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=' requested here
struct _LIBCPP_VISIBLE pair
                       ^
/usr/include/c++/v1/memory:1941:5: note: copy assignment operator is implicitly deleted because '__compressed_pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>
      >::__rep, std::__1::allocator<char> >' has a user-declared move constructor
    __compressed_pair(__compressed_pair&& __p)
    ^
1 error generated.

有人能建议我如何让它发挥作用吗?

我试图编译的文件甚至不需要包含任何C++11代码就可以发生此错误,仅凭"-stdlib=libc++"指令就足以使其崩溃。

感谢您的任何&所有协助,道格。

更新:嗨,代码很基本,但在尽可能使其基本的过程中,我遇到了这个错误:

Undefined symbols for architecture x86_64:
  "std::__1::cout", referenced from:
      _main in world.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
  "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

为了得到这个错误,我把我的代码剥离回这个:

#include <iostream>
int main( int argc, char *argv[] )
{
  std::cout << "Hi.n";
}

这让这看起来像是根本性的错误。

当我向编译器取出"-stdlib=libc++"指令时,我不会得到这个错误。

也许您应该考虑从llvm本身安装clang。这可以在这里找到。我不能100%确定,但也许macports或类似的软件已经针对与您安装的不同的gcc编译了您的版本。llvm下载是根据安装的gcc编译的,应该证明它与ABI兼容。

如果您按照llvm中的说明进行操作,您也可以升级libc++.dynlib,但请注意,MAC中的许多程序都依赖于此,因此您必须复制现有的lib(以防万一)。如果你想要流血,你可能需要深入研究这些变化。我在mac上做过这件事,它非常好,可以很好地编译c++11代码。

要构建libc++,请参阅此处

这里也有类似的问题。

简而言之,当发生这种情况时,是因为其中一个可能的过载被声明为禁止,因此过载解决方案失败。为了解决这个问题,你应该明确地使禁止的过载不成为调用的解决方案之一。

请参阅相关问题的公认答案,以获得非常详细和书面的解释。