Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libc++ - naming conflict for bind()?

Tags:

c++

clang

libc++

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?

like image 969
DigitalMan Avatar asked Dec 13 '22 05:12

DigitalMan


2 Answers

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()

like image 154
Cyril Leroux Avatar answered Dec 31 '22 20:12

Cyril Leroux


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().

like image 33
Dietmar Kühl Avatar answered Dec 31 '22 21:12

Dietmar Kühl