471,579 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,579 software developers and data experts.

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..
Expand|Select|Wrap|Line Numbers
  1. ../../../sockets.cpp: In constructor `network_class::network_class()':
  2. ../../../sockets.cpp:64: error: aggregate `addrinfo hints' has incomplete type a
  3. nd cannot be defined
  4. ../../../sockets.cpp:69: error: `getaddrinfo' undeclared (first use this functio
  5. n)
  6. ../../../sockets.cpp:69: error: (Each undeclared identifier is reported only onc
  7. e for each function it appears in.)
  8. ../../../sockets.cpp:70: error: `gai_strerror' undeclared (first use this functi
  9. on)
  10. ../../../sockets.cpp: In destructor `network_class::~network_class()':
  11. ../../../sockets.cpp:83: error: `freeaddrinfo' undeclared (first use this functi
  12. on)
  13. main.o:main.cpp:(.text+0x148): undefined reference to `network_class::gethostnam
  14. e()'
  15. 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++?)
Oct 10 '09 #1
7 6376
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:

Expand|Select|Wrap|Line Numbers
  1. memoryhandler.o:memoryhandler.cpp:(.text+0xc1c): undefined reference to `_GetPro
  2. cessMemoryInfo@12'
  3. errorhandler.o:errorhandler.cpp:(.text+0xf70): undefined reference to `_WSAGetLa
  4. stError@0'
  5. errorhandler.o:errorhandler.cpp:(.text+0x1840): undefined reference to `_WSAGetL
  6. astError@0'
  7. sockets.o:sockets.cpp:(.text+0xb8): undefined reference to `_WSAStartup@8'
  8. sockets.o:sockets.cpp:(.text+0x139): undefined reference to `_WSACleanup@0'
  9. sockets.o:sockets.cpp:(.text+0x1a9): undefined reference to `_gethostname@8'
  10. sockets.o:sockets.cpp:(.text+0x23c): undefined reference to `_getaddrinfo@16'
  11. sockets.o:sockets.cpp:(.text+0x2ee): undefined reference to `_gethostbyname@4'
  12. sockets.o:sockets.cpp:(.text+0x300): undefined reference to `_inet_ntoa@4'
  13. sockets.o:sockets.cpp:(.text+0x37b): undefined reference to `_gethostname@8'
  14. sockets.o:sockets.cpp:(.text+0x40e): undefined reference to `_getaddrinfo@16'
  15. sockets.o:sockets.cpp:(.text+0x4c0): undefined reference to `_gethostbyname@4'
  16. sockets.o:sockets.cpp:(.text+0x4d2): undefined reference to `_inet_ntoa@4'
  17. sockets.o:sockets.cpp:(.text+0x525): undefined reference to `_freeaddrinfo@4'
  18. sockets.o:sockets.cpp:(.text+0x541): undefined reference to `_freeaddrinfo@4'
  19. 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.
Oct 10 '09 #2
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.
Oct 10 '09 #3
Ok delete this thread, I worked it out.
Oct 10 '09 #4
9,065 Expert Mod 8TB
Rather than us deleting the thread why don't you post the answer for others to read?
Oct 11 '09 #5
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.
Oct 11 '09 #6
9,065 Expert Mod 8TB
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.
Oct 11 '09 #7
Ok I found out that _WIN32 is defined in cygwin.
And #undef _WIN32 doesnt work >(

Actually I'l use virtualbox.
Oct 11 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by James Hull | last post: by
2 posts views Thread by JustSomeGuy | last post: by
4 posts views Thread by Vish | last post: by
12 posts views Thread by Eugene A | last post: by
6 posts views Thread by Nadina | last post: by
4 posts views Thread by goberle | last post: by
12 posts views Thread by JS | last post: by
2 posts views Thread by Christoph Kukulies | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.