標籤:blog http os io 檔案 資料 2014 art
報錯內容:
1>LINK : warning LNK4076: 無效的增量狀態檔案“F:\VC_proj\Cproj\Debug\Cproj.ilk”;正在非增量連結
1>lase.obj : error LNK2028: 無法解析的標記(0A000013) "extern "C" int __stdcall closesocket(unsigned int)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A000016) "extern "C" int __stdcall recv(unsigned int,char *,int,int)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A000018) "extern "C" int __stdcall send(unsigned int,char const *,int,int)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A00001A) "extern "C" char * __stdcall inet_ntoa(struct in_addr)" ([email protected]@[email protected]@@Z),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A00001C) "extern "C" unsigned int __stdcall accept(unsigned int,struct sockaddr *,int *)" ([email protected]@[email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A00001D) "extern "C" int __stdcall listen(unsigned int,int)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A00001E) "extern "C" int __stdcall bind(unsigned int,struct sockaddr const *,int)" ([email protected]@[email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A00001F) "extern "C" unsigned short __stdcall htons(unsigned short)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A000020) "extern "C" unsigned long __stdcall htonl(unsigned long)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A000021) "extern "C" unsigned int __stdcall socket(int,int,int)" ([email protected]@[email protected]),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A000022) "extern "C" int __stdcall WSACleanup(void)" ([email protected]@$$J10YGHXZ),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2028: 無法解析的標記(0A000023) "extern "C" int __stdcall WSAStartup(unsigned short,struct WSAData *)" ([email protected]@[email protected]@@Z),該標記在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall closesocket(unsigned int)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall recv(unsigned int,char *,int,int)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall send(unsigned int,char const *,int,int)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" char * __stdcall inet_ntoa(struct in_addr)" ([email protected]@[email protected]@@Z),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" unsigned int __stdcall accept(unsigned int,struct sockaddr *,int *)" ([email protected]@[email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall listen(unsigned int,int)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall bind(unsigned int,struct sockaddr const *,int)" ([email protected]@[email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" unsigned short __stdcall htons(unsigned short)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" unsigned long __stdcall htonl(unsigned long)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" unsigned int __stdcall socket(int,int,int)" ([email protected]@[email protected]),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall WSACleanup(void)" ([email protected]@$$J10YGHXZ),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>lase.obj : error LNK2019: 無法解析的外部符號 "extern "C" int __stdcall WSAStartup(unsigned short,struct WSAData *)" ([email protected]@[email protected]@@Z),該符號在函數 "int __cdecl wmain(int,wchar_t * * const)" ([email protected]@[email protected]) 中被引用
1>F:\VC_proj\Cproj\Debug\Cproj.exe : fatal error LNK1120: 24 個無法解析的外部命令
源碼:
#include <stdafx.h>
#include <Winsock2.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
//載入通訊端庫
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(1,1);
err=WSAStartup(wVersionRequested, &wsaData);
if(err!=0)
{
return 0 ;
}
if(LOBYTE(wsaData.wVersion)!=1 ||
HIBYTE(wsaData.wVersion)!=1 )
{
WSACleanup();
return 0;
}
//建立用於監聽的通訊端
SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(6000);
//綁定通訊端
bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
//將通訊端設為監聽模式,準備接收客戶請求
listen(sockSrv,5);
SOCKADDR_IN addrClient;
int len = sizeof(SOCKADDR);
while(1)
{
SOCKET sockConn=accept(sockSrv,(SOCKADDR*)&addrClient,&len);
char sendBuf[100];
sprintf(sendBuf,"Welcome %s to here",inet_ntoa(addrClient.sin_addr));
//發送資料
send(sockConn,sendBuf,strlen(sendBuf)+1,0);
char recvBuf[100];
//接收資料
recv(sockConn,recvBuf,100,0);
//列印接收的資料
printf("%s \n",recvBuf);
//關閉通訊端
closesocket(sockConn);
}
return 0;
}
解決方案:
項目->xx屬性->配置屬性->命令列->附加選項(也就是添加靜態串連庫的地方)ws2_32.lib