Subject: Re: INVALID_SOCKET symbol conflict

Re: INVALID_SOCKET symbol conflict

From: Lawson <>
Date: Fri, 2 Mar 2012 08:12:32 -0800 (PST)


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:


and SNMP++ defines it as:
#define INVALID_SOCKET ((SnmpSocket)(~0)) // value for invalid socket

Note that the SNMP++ header has an #ifdef. If I make the libssh2 come first, then the ifdef will stop it from being redefined... but it will be the wrong value (and type) for SNMP++.

I'm sure I can craft a workaround. 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.

- matt

--- On Fri, 3/2/12, Alexander Lamaison <> wrote:

> From: Alexander Lamaison <>
> Subject: Re: INVALID_SOCKET symbol conflict
> To: "libssh2 development" <>
> Date: Friday, March 2, 2012, 7:43 AM
> On 2 March 2012 15:13, Lawson <>
> wrote:
> >
> > I notice that nearly all the defines in libssh2.h use
> the LIBSSH2_ prefix, except for INVALID_SOCKET.  It seems
> to be on purpose but I don't understand why.  Is it a
> Windows thing?
> It is a Windows Winsock constant that represents the only
> value
> returned by socket() that is guaranteed not to be a valid
> socket
> handle.  libssh2 defines it in the header for other
> platforms to help
> with portable programming.
> > My issue is that I'm writing an application (on Linux)
> which includes headers from multiple libraries, and some of
> them also set this symbol to a conflicting value.
> I believe the difference is because on some platforms
> sockets are
> signed ints and others they are unsigned ints.  Can you
> give more
> details about the conflict.  Error messages etc.
> Alex
> --
> Easy SFTP for Windows Explorer (
> _______________________________________________
> libssh2-devel

Received on 2012-03-02