CLion undefined reference to `WSAStartup@8'

初用CLion,在编写一个简单网络程序时,报了这个错

“C:\Program Files\JetBrains\CLion 2017.3.3\bin\cmake\bin\cmake.exe” –build C:\Users\foyou\CLionProjects\CL01\cmake-build-debug –target CL01 – -j 4
[ 50%] Linking CXX executable CL01.exe
CMakeFiles\CL01.dir/objects.a(main.cpp.obj): In function main':
C:/Users/foyou/CLionProjects/CL01/main.cpp:6: undefined reference to
WSAStartup@8’
C:/Users/foyou/CLionProjects/CL01/main.cpp:8: undefined reference to socket@12'
C:/Users/foyou/CLionProjects/CL01/main.cpp:13: undefined reference to
inet_addr@4’
C:/Users/foyou/CLionProjects/CL01/main.cpp:14: undefined reference to htons@4'
C:/Users/foyou/CLionProjects/CL01/main.cpp:15: undefined reference to
bind@12’
C:/Users/foyou/CLionProjects/CL01/main.cpp:17: undefined reference to listen@8'
C:/Users/foyou/CLionProjects/CL01/main.cpp:21: undefined reference to
accept@12’
C:/Users/foyou/CLionProjects/CL01/main.cpp:24: undefined reference to send@16'
C:/Users/foyou/CLionProjects/CL01/main.cpp:26: undefined reference to
closesocket@4’
C:/Users/foyou/CLionProjects/CL01/main.cpp:27: undefined reference to closesocket@4'
C:/Users/foyou/CLionProjects/CL01/main.cpp:29: undefined reference to
WSACleanup@0’
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: * [CL01.exe] Error 1
CMakeFiles\CL01.dir\build.make:95: recipe for target ‘CL01.exe’ failed
CMakeFiles\Makefile2:66: recipe for target ‘CMakeFiles/CL01.dir/all’ failed
mingw32-make.exe[2]: * [CMakeFiles/CL01.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target ‘CMakeFiles/CL01.dir/rule’ failed
mingw32-make.exe[1]: * [CMakeFiles/CL01.dir/rule] Error 2
Makefile:117: recipe for target ‘CL01’ failed
mingw32-make.exe: * [CL01] Error 2

尝试了好久,终于解决了
方法:
在CMakeLists.txt文件中添加如下代码:

link_libraries(ws2_32)
//*添加位置要注意*
  • 13
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值