C语言网络编程问题
程序代码:
#include "windows.h" #include "winsock2.h" int WSA_return; WSADATA wSAData; HOSTENT *host_entry; char host_name[256]; char host_address[256]; APIENTRY int WinMain(HINSTANCE hIstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { WSA_return=WSAStartup(0x0101,&wSAData); if(WSA_return==0) { gethostname(host_name,256); host_entry=gethostbyname(host_name); if(host_entry!=0) { wsprintf(host_address,"%d.%d.%d.%d", (host_entry->h_addr_list[0][0]&0x00ff), (host_entry->h_addr_list[0][1]&0x00ff), (host_entry->h_addr_list[0][2]&0x00ff), (host_entry->h_addr_list[0][3]&0x00ff) ); MessageBox(NULL,host_address,host_name,MB_OK); } } WSACleanup(); return 0; } 我用C-Free 5.0 写的,编译后出现了错误 --------------------配置: mingw5 - GUI Debug, 编译器类型: MinGW-------------------- 检查文件依赖性... 正在编译 C:\Users\hp\Documents\C-Free\Temp\未命名1.cpp... [Warning] C:\Users\hp\Documents\C-Free\Temp\未命名1.cpp:29:2: warning: no newline at end of file 正在连接... [Error] C:\Users\hp\Documents\C-Free\Temp\未命名1.cpp:11: undefined reference to `WSAStartup@8' [Error] C:\Users\hp\Documents\C-Free\Temp\未命名1.cpp:14: undefined reference to `gethostname@8' [Error] C:\Users\hp\Documents\C-Free\Temp\未命名1.cpp:15: undefined reference to `gethostbyname@4' [Error] C:\Users\hp\Documents\C-Free\Temp\未命名1.cpp:27: undefined reference to `WSACleanup@0' [Error] collect2: ld returned 1 exit status 构建中止 未命名1: 5 个错误, 1 个警告 这该怎么办啊?请教高手……