undefined reference to `__imp_WSAStartup'

来源:互联网 发布:配音软件 语气 编辑:程序博客网 时间:2024/06/06 04:17
<span style="font-size:18px;"><strong>#include <iostream>#include <winsock2.h>#include <stdio.h>#define SERVER_PORT 8082#pragma comment(lib, "ws2_32")/*关于WSAStartup方法和WSACleanup方法引用出错的解决:错误:编译的时候出现 undefined reference to `__imp_WSAStartup'undefined reference to `__imp_WSACleanup'在一般编译器中不会直接连接编译wsock动态库,需要手动添加库首先可以尝试代码中直接引入动态库,#pragam comment(lib,"ws2_32");如果不行再手动添加库在vc中,点项目(project-->project option)在makefile中输入-L"ws2_32" 在dvc C++中点击工具(Tool)-->编译选项(Compile Option)在编译命令框中输入-lwsokt32*/using namespace std; int main(){ int produrce_Step = 0;WORD winSocketVersion;WSADATA wsaDATA;SOCKET listen_Socket,server_Sokcet;struct sockaddr_in client_socket_addr;  //客户端地址信息 struct sockaddr_in ser_socket_addr;  //服务器端地址信息 winSocketVersion = MAKEWORD(2,2);int return_num;//WinSocket 初始化 return_num = WSAStartup(winSocketVersion,&wsaDATA);if(return_num!=0){cout<<"WSAStartup() failed!"<<endl;return 0; } //确认支持winsocket版本2.2 if(LOBYTE(wsaDATA.wVersion)!=2||HIBYTE(wsaDATA.wVersion)!=2){WSACleanup();cout<<"Invalid WinSockt Version!"<<endl;return 0;}produrce_Step ++;cout<<produrce_Step<<"***Initial WinSocket Successfully!"<<endl;return 0;}</strong></span>


1 0
原创粉丝点击