I haven't seen this issue before and wasn't exactly sure how to even search for a solution to this problem because i'm not sure what to even look for. I have some code using sockets to read/write to my linux device driver. This code is tested and works as is.
I would like to add a mutex to my program for thread safety reasons but as soon as I add #include <mutex>
to my program's main.cpp file and ONLY that line the <sys/socket.h> bind()
function throws an error at compile time...
Here is the line causing the problem once I #include <mutex>
and change nothing else in my code
if (bind(sock_fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0)
dp_comm.cpp: In function 'int setup_socket_to_dev(const char*, int*)': dp_comm.cpp:160:64: error: no match for 'operator<' in 'std::bind(_Functor&&, _ArgTypes&& ...) [with _Functor = int&, _ArgTypes = {sockaddr*, unsigned int}, typename std::_Bind_helper<_Functor, _ArgTypes>::type = std::_Bind]((* &((sockaddr*)(& saddr))), (* &20u)) < 0'
I also tried to create an int and have it equal the return value of bind()
int ret_bind = bind(sock_fd, (struct sockaddr *)&saddr, sizeof(saddr));
dp_comm.cpp: In function 'int setup_socket_to_dev(const char*, int*)': dp_comm.cpp:160:71: error: cannot convert 'std::_Bind_helper::type {aka std::_Bind}' to 'int' in initialization
Why does #include <mutex>
cause my compiler to throw a fit at the bind()
call?
The only way the code will compile when I #include <mutex>
is the following
bind(sock_fd, (struct sockaddr *)&saddr, sizeof(saddr));
What's going on?