0

i am using Netbeans 8.1 IDE with g++ compiler (cygwin) to build a custome Socket class whose implementation is well defined in socket.cpp, and declared in socket.h as shown below:

//socket.h

#ifndef SOCKET_H
#define SOCKET_H
  
#include <windows.h>
#include <winsock2.h>     /*Code builds successfully if this line is commented. errors otherwise*/

class Socket {
    
public: 
    Socket(){std::cout << "Testing: Inside socket constructor ..." << endl;}
    Socket(const Socket&);
    virtual ~Socket();
    Socket& operator=(Socket&);
    
    void Close();

protected: 

    Socket(SOCKET s);   /*Windows socket handle, defined in <winsock2.h>*/
     
    SOCKET s_;

    int* refCounter_;

private:
    static bool Start();
    static void End();
    static int nofSockets_;

};

#endif /* SOCKET_H */

now, i test-drove it like this:

//main.cpp

#include "socket.h"

int main() {
    Socket socket;
    return 0;
}

Above code built successfully when winsock2.h is removed, error otherwise. Honestly i am new to the netbeans IDE and i can't understand what am doing wrong. I Dont know what the IDE requires of me either. i need your help to debugg this please. Thanks. Here's the error:

cd 'C:\wamp\www\klandestine'
C:\cygwin64\bin\make.exe -f Makefile CONF=Debug clean
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory '/cygdrive/c/wamp/www/klandestine'
rm -f -r build/Debug
rm -f dist/Debug/Cygwin-Windows/klandestine.exe
make[1]: Leaving directory '/cygdrive/c/wamp/www/klandestine'

CLEAN SUCCESSFUL (total time: 656ms)
cd 'C:\wamp\www\klandestine'
C:\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/wamp/www/klandestine'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/klandestine.exe
make[2]: Entering directory '/cygdrive/c/wamp/www/klandestine'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/Cygwin-Windows/main.o.d" -o build/Debug/Cygwin-Windows/main.o main.cpp
In file included from /usr/include/w32api/winsock2.h:56:0,
                 from socket.h:12,
                 from main.cpp:14:
/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types.      This can cause runtime problems with W32 sockets" [-Wcpp]
 #warning "fd_set and associated macros have been defined in sys/types.  \
  ^
In file included from socket.h:12:0,
                 from main.cpp:14:
/usr/include/w32api/winsock2.h:995:123: error: conflicting declaration of C function 'int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, PTIMEVAL)'
   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
                                                                                                                           ^
In file included from /usr/include/sys/types.h:68:0,
                 from /usr/include/pthread.h:14,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/x86_64-pc-cygwin/bits/gthr-default.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/x86_64-pc-cygwin/bits/gthr.h:148,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/ext/atomicity.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/bits/ios_base.h:39,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/ios:42,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/ostream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/include/c++/iostream:39,
                 from main.cpp:9:
/usr/include/sys/select.h:73:5: note: previous declaration 'int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, timeval*)'
 int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
     ^
make[2]: *** [nbproject/Makefile-Debug.mk:69: build/Debug/Cygwin-Windows/main.o] Error 1
make[2]: Leaving directory '/cygdrive/c/wamp/www/klandestine'
make[1]: *** [nbproject/Makefile-Debug.mk:60: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/wamp/www/klandestine'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)
Osagie Odigie
  • 281
  • 1
  • 3
  • 13

0 Answers0