C++0x Threads and Sockets



我正在写一个c++程序(用于arm架构),它连接到can接口。我使用标准的socket, bind, recv和send函数。现在我在这一点上,我需要外包一些功能到线程。为此,我想使用c++ 0x线程,因为我在这里某处读到,由于兼容性问题,pthreads不应该在c++中使用。

所以i包含了线程库#include <thread>。并添加到我的编译器调用选项-Wno-psabi -std=c++0x -lpthread

(-Wno-psabi是用来禁用note: the mangling of ‘va_list’ has changed in GCC 4.4消息的)

我得到的错误是:

25: error: no match for ‘operator<’ in ‘std::bind(_Functor, _ArgTypes ...) [with _Functor = int, _ArgTypes = sockaddr*, unsigned int](((sockaddr*)(&((can*)this)->can::addr)), 16u) < 0

/usr/arm-linux-gnueabi/include/c++/4.4.5/system_error:258: note: candidates are: bool std::operator<(const std::error_condition&, const std::error_condition&)

/usr/arm-linux-gnueabi/include/c++/4.4.5/system_error:177: note: bool std::operator<(const std::error_code&, const std::error_code&)

我认为线程库中的bind函数覆盖了套接字中的bind函数。

我如何告诉编译器何时使用什么函数?

我使用arm-linux-gnueabi-g++版本4.4.5

尝试使用::bind作为C函数,或者不使用using namespace std并完全限定您的std函数调用。

也有中间解决方案,参见:

    如何在c++中正确使用名称空间?c++中的
  • 命名空间

最新更新