3

I can't get a C++11 project using clang 3.1 to compile. The command to the compiler is this:

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

And the error I get, since I included the "-stdlib=libc++" directive, is this:

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.

Can anyone advise me on how I can get this to work?

The file I'm trying to compile doesn't even have to include any C++11 code for this error to occur, the "-stdlib=libc++" directive alone is enough to make it break.

Thanks for any & all assistance, Doug.

UPDATE: Hi -- the code is pretty basic, but in making it as basic as possible, I came across this error:

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)

To get this error, I stripped my code back to this:

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

Which makes this look like something pretty fundamentally wrong.

I don't get this error when I take out the "-stdlib=libc++" directive to the compiler.

4

2 回答 2

1

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

如果您遵循 llvm 中的说明,您也可以升级 libc++.dynlib,但请注意 MAC 中的许多 progs 都依赖于此,因此您必须复制现有 lib(以防万一)。如果你想要最前沿,你可能需要深入研究这些变化。我已经在 Mac 上完成了这个,它非常好,可以编译 c++11 代码就好了。

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

于 2012-07-22T20:16:26.980 回答
1

这里有一个类似的问题。

简而言之,发生这种情况是因为其中一个可能的重载被声明为禁止,因此重载决议失败。为了解决这个问题,您应该明确地进行强制转换,以使禁止的重载不是调用的解决方案之一。

有关非常详细且写得很好的解释,请参阅已接受的链接问题的答案。

于 2016-09-11T12:39:09.997 回答