【网络SOCKET编程】DEV-C/C++ 编译时出现undefined reference to `WSAStartup@8'等错误解决办法

转载自:http://liuzhigong.blog.163.com/blog/static/178272375201171562749825/

【网络SOCKET编程】DEV-C/C++ 编译时出现undefined reference to `WSAStartup@8'等错误解决办法  

在DEV-C++中编译含WINSOCK的代码经常会出现这样的编译错误
undefined reference to `inet_addr@4'
undefined reference to `gethostbyname@4'
undefined reference to `WSAGetLastError@0'
undefined reference to `inet_ntoa@4'
undefined reference to `WSAStartup@8'
undefined reference to `inet_ntoa@4'
undefined reference to `socket@12'
undefined reference to `htons@4'
undefined reference to `bind@12'
undefined reference to `listen@8'
undefined reference to `accept@12'
undefined reference to `recv@16'
undefined reference to `send@16'
undefined reference to `shutdown@8'
undefined reference to `closesocket@4'
undefined reference to `closesocket@4'
undefined reference to `WSACleanup@0'

解决办法:
工具 -> 编译选项 -> 编译器    选中连接器命令行并加入下列命令:-lwsock32

你可能感兴趣的:(C/C++基础学习)