0
votes

I've started another program to run Winsock in C language on Windows7.

I found this help on msdn: http://msdn.microsoft.com/en-us/library/windows/desktop/ms737591%28v=vs.85%29.aspx

This program is not working and showing these errors:

$ gcc ak1.c -o ak1.exe -lwsock32 -lws2_32 -lAdvapi32 -lmswsock

C:\Users\rahul\AppData\Local\Temp\ccWqZC7C.o:ak1.c:(.text+0x109): undefined re ference to `getaddrinfo'

C:\Users\rahul\AppData\Local\Temp\ccWqZC7C.o:ak1.c:(.text+0x1fa): undefined re ference to `freeaddrinfo'

c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\a mit\AppData\Local\Temp\ccWqZC7C.o: bad reloc address 0x20 in section `.eh_frame'

c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation

collect2.exe: error: ld returned 1 exit status

Is this error related to MICROSOFT SDK for Windows7, means these libraries are not added on my system. I checked "Advapi32" is not under my micrsoft SDK.

Help please !!!

1

1 Answers

0
votes

You're using GCC (presumably MinGW) which doesn't use Microsoft's SDK. getaddrinfo() and freeaddrinfo() are declared in MinGW's ws2tcpip.h implementation, but only if WinXP or later is targeted.

Add -D_WIN32_WINNT=0x0501 to your compiler command line to target XP.