After surprisingly little hacking about, I managed to get libc++ installed on my Linux box (as libstdc++ is missing things). Unfortunately, a bit of my existing code has now broken, on account of functions with the same name.
Normally, and in the manner I need, bind() relates to sockets. However, libc++ came with its own bind() function, which is basically this but without a convenient namespace to separate them. In accordance with Murphy's Law, the compiler attempts to use the wrong function, and spits out an error. NetBeans does not see any issue, because it's actually looking in the sys/socket.h file, as it very well should.
So, with both functions basically beyond the scope of my control, how would I tell the compiler (clang++) that it should look in a specific header and nowhere else for that function?
I had a conflict between bind()
from <WinSock2.h>
and std::bind()
(I was using using namespace std;
)
I just added ::
before the method call and it worked !
bind()
=> ::bind()
First, this hasn't anything to do with Murphy, I'd think: the choice of the bind()
template is probably just the better match. The declaration of std::bind()
is in namespace std
, however, at least in the version of the header file I'm looking at. Is it possible that your source file contains a using directive? (in which case you deserve all the pain you asked for)
If there is no using directive, the non-template version should be a better match if the arguments match exactly. If this still doesn't help, you can create a forwarding function for the bind()
function from <sys/socket.h>
, let's say avoid_conflict_bind()
which is the only function defined in the translation unit, i.e. it would only include <sys/socket.h>
and not <functional>
. This way there is no choice for the bind()
function this function forwards to and you can then use avoid_conflict_bind()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With