我正在编写一个连接到 CAN 接口(interface)的 C++ 程序(用于 Arm 架构)。 我为此使用标准套接字、绑定(bind)、接收和发送函数。 现在我需要将一些功能外包到线程中。 为此,我想使用 C++0x 线程,因为我在这里读到,由于兼容性问题,pthreads 不应在 c++ 中使用。
所以我包括线程库 #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
最佳答案
尝试对 C 函数使用 ::bind
,或者不要使用 using namespace std
并完全限定您的 std 函数调用。
还有中间解决方案,参见:
关于multithreading - C++0x 线程和套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16562166/