我的代码如下:
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
if (WSAStartup (MAKEWORD(2,0), &wsaData) != 0)
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
} 最近报了这些错误:
Linking...
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__inet_ntoa@4
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__gethostname@8
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/Dia1.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.
请问是什么原因,谢谢大家了我头文件 中只用了include <winsock.h>
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
if (WSAStartup (MAKEWORD(2,0), &wsaData) != 0)
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
} 最近报了这些错误:
Linking...
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__inet_ntoa@4
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__gethostname@8
Dia1Dlg.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/Dia1.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.
请问是什么原因,谢谢大家了我头文件 中只用了include <winsock.h>
===========================================
2.0版的SOCK要 #include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")