undefined reference to `WSAStartup@8' C++套接字编程出现的问题

本文详细介绍了如何在CodeBlocks中正确配置ws2_32.dll,以便于支持网络应用程序的开发。通过在设置中的编译器选项添加此DLL文件,可以确保应用程序能够顺利调用Windows Sockets API。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

codeblocks下解决办法:

1:左上角工具栏settings->complier:

点击add 

 

在windows/system32目录下 选择ws2_32.dll(ws2_32.dll是Windows Sockets应用程序接口, 用于支持Internet和网络应用程序)

OK!

 

||=== Build: Debug 在 server 中 (编译器: GNU GCC Compiler) ===| D:\学习\计网\TCP\server\main.cpp|6|warning: ignoring #pragma comment [-Wunknown-pragmas]| D:\学习\计网\TCP\server\main.cpp||In function 'int main()':| D:\学习\计网\TCP\server\main.cpp|15|warning: unused variable 'sin_size' [-Wunused-variable]| obj\Debug\main.o||In function `main':| D:\学习\计网\TCP\server\main.cpp|18|undefined reference to `__imp_WSAStartup'| D:\学习\计网\TCP\server\main.cpp|24|undefined reference to `__imp_socket'| D:\学习\计网\TCP\server\main.cpp|26|undefined reference to `__imp_WSACleanup'| D:\学习\计网\TCP\server\main.cpp|34|undefined reference to `__imp_htonl'| D:\学习\计网\TCP\server\main.cpp|35|undefined reference to `__imp_htons'| D:\学习\计网\TCP\server\main.cpp|38|undefined reference to `__imp_bind'| D:\学习\计网\TCP\server\main.cpp|40|undefined reference to `__imp_closesocket'| D:\学习\计网\TCP\server\main.cpp|41|undefined reference to `__imp_WSACleanup'| D:\学习\计网\TCP\server\main.cpp|46|undefined reference to `__imp_listen'| D:\学习\计网\TCP\server\main.cpp|48|undefined reference to `__imp_closesocket'| D:\学习\计网\TCP\server\main.cpp|49|undefined reference to `__imp_WSACleanup'| D:\学习\计网\TCP\server\main.cpp|57|undefined reference to `__imp_accept'| D:\学习\计网\TCP\server\main.cpp|62|undefined reference to `__imp_inet_ntoa'| D:\学习\计网\TCP\server\main.cpp|65|undefined reference to `__imp_recv'| D:\学习\计网\TCP\server\main.cpp|75|undefined reference to `__imp_send'| D:\学习\计网\TCP\server\main.cpp|78|undefined reference to `__imp_closesocket'| ||error: ld returned 1 exit status| ||=== 构建 失败: 17 error(s), 2 warning(s) (0 分, 0 秒) ===| 出现以上问题,如何解决
05-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值