|
From: James S. <jam...@op...> - 2006-08-25 05:27:01
|
Hi All,
I've googled for this for a while now and I'm not sure what to do next.
I have a small c program that calls getaddrinfo and freeaddrinfo.
I have the header file included for ws2tcpip.h.
When I compile with
gcc -Wall -o prog main.c -lws2_32
I get warnings about implicit declarations of the 2 functions and
undefined references to the 2 functions from the linker.
In the ws2tcpip.h I see
#if (_WIN32_WINNT >= 0x0501)
---declaration of getaddrinfo
#else
/* FIXME ...
When I print the value of _WIN32_WINNT I get 0x400 so obviously the
function isn't declared. That explains the implicit declarations
warning. But what about the undefined references? The functions are in
the library ws2_32.a.
What do I need to do to resolve this? Is it a MinGW version or a
Windows version that needs updating? Or something completely different?
I've attached a smaller test case that behaves similarly.
Regards,
James.
/*
gcc -Wall -o test test.c -lws2_32
test.c: In function `main':
test.c:27: warning: implicit declaration of function `getaddrinfo'
C:/DOCUME~1/James/LOCALS~1/Temp/ccw5baaa.o(.text+0xeb):test.c: undefined
reference to `getaddrinfo'
collect2: ld returned 1 exit status
*/
#include <windows.h>
#include <stdio.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#define DEF_PORT "27015"
int main(int argc, char **argv) {
int rv;
WSADATA wsaData;
struct addrinfo *result = NULL, hints;
rv = WSAStartup((short)0x0202, &wsaData);
if (rv != 0) {
printf("WSAStartup failed: %d\n", rv);
return 1;
}
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_flags = AI_PASSIVE;
rv = getaddrinfo(NULL, DEF_PORT, &hints, &result);
if (rv != 0) {
printf("getaddrinfo failed: %d\n", rv);
WSACleanup();
return 1;
}
WSACleanup();
return 0;
}
|