Subject: Re: INVALID_SOCKET symbol conflict

Re: INVALID_SOCKET symbol conflict

From: Alexander Lamaison <>
Date: Fri, 2 Mar 2012 16:27:45 +0000

On 2 March 2012 16:12, Lawson <> wrote:
> Hi,
> Thanks for the prompt reply.  The compile warning is:
> In file included from /usr/local/include/libssh2/libssh2.h:140:1: warning: "INVALID_SOCKET" redefined
> In file included from /usr/local/include/snmp_pp/snmp_pp.h:71,
>                 from snmpThreadData.h:13,
>                 from snmpThreadData.cpp:4:
> /usr/local/include/snmp_pp/uxsnmp.h:49:1: warning: this is the location of the previous definition
> So the conflict is I end up with headers both from libssh2 and the snmp++ library (
> Libssh2 defines it as:
> #define INVALID_SOCKET -1
> and SNMP++ defines it as:
> #define INVALID_SOCKET ((SnmpSocket)(~0)) // value for invalid socket
> #endif

I believe that both these values actually result in the same thing: an
int-size chunk of memory with all bits set.

> Note that the SNMP++ header has an #ifdef.

One way to deal with this is to do the same thing so whichever one
comes first wins.

> Mostly I was perplexed at why two different libraries which are otherwise both disciplined about defining their constants with a namespace prefix both chose to define this one symbol like this, like it was some magical special symbol that everyone  knew about.

I guess it *is* a magical special symbol everyone knows about ... if
you come from the Windows world.

My personal preference would be to declare our own constant, something
like LIBSSH2_INVALID_SOCKET that is INVALID_SOCKET on windows and -1
elsewhere. Then we use that in the libssh2 source code rather than


Easy SFTP for Windows Explorer (
Received on 2012-03-02