Cygwin sockets: getaddrinfo undeclared

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Adam01
    New Member
    • Aug 2008
    • 83

    Cygwin sockets: getaddrinfo undeclared

    Im using cygwin to test the code of a server I am writing.
    I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h.

    And this is the output..
    Code:
    ../../../sockets.cpp: In constructor `network_class::network_class()':
    ../../../sockets.cpp:64: error: aggregate `addrinfo hints' has incomplete type a
    nd cannot be defined
    ../../../sockets.cpp:69: error: `getaddrinfo' undeclared (first use this functio
    n)
    ../../../sockets.cpp:69: error: (Each undeclared identifier is reported only onc
    e for each function it appears in.)
    ../../../sockets.cpp:70: error: `gai_strerror' undeclared (first use this functi
    on)
    ../../../sockets.cpp: In destructor `network_class::~network_class()':
    ../../../sockets.cpp:83: error: `freeaddrinfo' undeclared (first use this functi
    on)
    main.o:main.cpp:(.text+0x148): undefined reference to `network_class::gethostnam
    e()'
    collect2: ld returned 1 exit status
    I checked the sys/socket file, and it includes cygwin/socket, which doesnt declare any functions. And getaddrinfo is not declared in sys/socket.

    I take it I am missing some sort of package, but which one?

    (And by the way, is there any other way to tell g++ where to put the .object files rather than being the object dir when running g++?)
  • Adam01
    New Member
    • Aug 2008
    • 83

    #2
    Ok turned out I needed to use the -mno-cygwin option for g++.
    But help the on the object file directory would be nice.

    Edit: Now I seem to be undefined linking errors:

    Code:
    memoryhandler.o:memoryhandler.cpp:(.text+0xc1c): undefined reference to `_GetPro
    cessMemoryInfo@12'
    errorhandler.o:errorhandler.cpp:(.text+0xf70): undefined reference to `_WSAGetLa
    stError@0'
    errorhandler.o:errorhandler.cpp:(.text+0x1840): undefined reference to `_WSAGetL
    astError@0'
    sockets.o:sockets.cpp:(.text+0xb8): undefined reference to `_WSAStartup@8'
    sockets.o:sockets.cpp:(.text+0x139): undefined reference to `_WSACleanup@0'
    sockets.o:sockets.cpp:(.text+0x1a9): undefined reference to `_gethostname@8'
    sockets.o:sockets.cpp:(.text+0x23c): undefined reference to `_getaddrinfo@16'
    sockets.o:sockets.cpp:(.text+0x2ee): undefined reference to `_gethostbyname@4'
    sockets.o:sockets.cpp:(.text+0x300): undefined reference to `_inet_ntoa@4'
    sockets.o:sockets.cpp:(.text+0x37b): undefined reference to `_gethostname@8'
    sockets.o:sockets.cpp:(.text+0x40e): undefined reference to `_getaddrinfo@16'
    sockets.o:sockets.cpp:(.text+0x4c0): undefined reference to `_gethostbyname@4'
    sockets.o:sockets.cpp:(.text+0x4d2): undefined reference to `_inet_ntoa@4'
    sockets.o:sockets.cpp:(.text+0x525): undefined reference to `_freeaddrinfo@4'
    sockets.o:sockets.cpp:(.text+0x541): undefined reference to `_freeaddrinfo@4'
    collect2: ld returned 1 exit status
    I have no idea why WSAstartup is showing up (the function and the header are in #ifdef _WIN32 wrappers.

    Comment

    • Adam01
      New Member
      • Aug 2008
      • 83

      #3
      Sorry I couldnt edit the post above, but compiling on centOS, compiles and links fine. But running, the only output I get is:
      Segmentation fault

      No warnings/ouput popped up whilst g++ was compiling/linking.

      Comment

      • Adam01
        New Member
        • Aug 2008
        • 83

        #4
        Ok delete this thread, I worked it out.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Rather than us deleting the thread why don't you post the answer for others to read?

          Comment

          • Adam01
            New Member
            • Aug 2008
            • 83

            #6
            Ok, I used valgrind to track down the memory errors.

            Turns out that gethostbyname(" ") returned null on centos and I did check it before using it.

            I still cant compile this on cygwin.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              I wish I could help but I have always felt that cygwin was the work of the devil and avoid it as much as possible, hence I don't know much about it, sorry.

              Comment

              • Adam01
                New Member
                • Aug 2008
                • 83

                #8
                Ok I found out that _WIN32 is defined in cygwin.
                And #undef _WIN32 doesnt work >(
                Ideas?

                Actually I'l use virtualbox.

                Comment

                Working...