When you look at some call, look down at the bottom of the description. You will find
something like
Requirements
Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows
Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header: Declared in Winsock2.h.
Library: Use Ws2_32.lib.
Note the two relevant lines: the Header: line tells you what header file to include, and
the Library: line tells you what library to add to your link to avoid the unresolved
references. (The above lines were copied directly from the closesocket documentation)
joe
On 30 Nov 2006 06:32:03 -0800, "june" <gahaja2000...yahoo.com> wrote:
>Hello? I'm June from S.Korea.
>I'm sorry if I am at a wrong place for my question.
>I'm practicing echo client code. Below is what I copied from a
>textbook.
>The problem is,
>there're 0 error, 0 warning at compiling.
>But There're 10 errors at Building EXE files.
>How can I troubleshoot them? I already #included winsock2.h, which has
>the definition for the functions listed in the 10 error messages.And
>the help says the linker doesn't find definition for the functions
>listed.
>Thanks for reading and still I'm not sure if I'm at a right place to
>ask. But hope you will help me.
>
>--Configuration: echo - Win32
>Debug--
>Linking...
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__WSACleanup...0
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__closesocket...4
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__recv...16
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__send...16
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__connect...12
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__htons...4
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__inet_addr...4
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__socket...12
>echo_client_win.obj : error LNK2001: unresolved external symbol
>__imp__WSAStartup...8
>Debug/echo.exe : fatal error LNK1120: 9 unresolved externals
>Error executing link.exe.
>echo.exe - 10 error(s), 0 warning(s)
>
>
>
>
>/*echo_client_win.c*/
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>#include <winsock2.h>
>#define BUFSIZE 1024
>void ErrorHandling(char *message);
>int main(int argc, char **argv)
>{
> WSADATA wsaData;
> SOCKET hSocket;
> char message[BUFSIZE];
> int strLen;
> SOCKADDR_IN servAddr;
> if(argc!=3)
> {
> printf("Usage : %s <IP> <port>/n", argv[0]);
> exit(1);
> }
> if(WSAStartup(MAKEWORD(2, 2), &wsaData) !=0) /* load winsock 2.2
>dll*/
> ErrorHandling("WSAStartup() error!");
> hSocket=socket(PF_INET, SOCK_STREAM, 0);
> if(hSocket == INVALID_SOCKET)
> ErrorHandling("socket() error");
> memset(&servAddr, 0, sizeof(servAddr));
> servAddr.sin_family=AF_INET;
> servAddr.sin_addr.s_addr=inet_addr(argv[1]);
> servAddr.sin_port=htons(atoi(argv[2]));
> if(connect(hSocket, (SOCKADDR*)&servAddr,
> sizeof(servAddr))==SOCKET_ERROR)
> ErrorHandling("connect() error!");
> while(1)
> {
> fputs("hello world! (q to quit) : ", stdout);
> fgets(message, BUFSIZE, stdin); /* input from data console to be sent
>*/
> if(!strcmp(message, "q/n"))
> break;
> send(hSocket, message, strlen(message),0); /* send msg */
> strLen=recv(hSocket, message, BUFSIZE-1, 0); /*receive msg*/
> message[strLen]=0;
> printf("msg from server : %s /n", message);
> }
> closesocket(hSocket);
> WSACleanup();
> return 0;
>}
>void ErrorHandling(char *message)
>{
> fputs(message, stderr);
> fputc('/n', stderr);
> exit(1);
>}
Joseph M. Newcomer [MVP]
email: newcomer...flounder.com
Web:
http://www.flounder.comMVP Tips:
http://www.flounder.com/mvp_tips.htm