【问题标题】:Can't compile C code with Winsock implementation [duplicate]无法使用 Winsock 实现编译 C 代码 [重复]
【发布时间】:2022-01-12 11:05:53
【问题描述】:

我对编程还是很陌生。我正在尝试使用 winsock.h 使用服务器和客户端制作一个刽子手游戏,但我似乎无法编译它。尝试从 cmd 窗口编译它时出现以下错误,即使我已经修改了编译器链接器设置(在代码块中):

C:\Users\USER\Documents\Maestria\Computacion\prueva2>gcc cliente.c -o client.exe
undefined reference to `WSAStartup@8'
undefined reference to `socket@12'
undefined reference to `htons@4'
undefined reference to `inet_addr@4'
undefined reference to `connect@12'
undefined reference to `closesocket@4'
undefined reference to `send@16'
undefined reference to `recv@16'
undefined reference to `closesocket@4'
undefined reference to `WSACleanup@0'
collect2.exe: error: ld returned 1 exit status

有人知道可能是什么问题吗?

【问题讨论】:

  • 你需要链接必要的库,查看被调用函数的文档。
  • this 回答你的问题了吗?

标签: c sockets mingw codeblocks winsock


【解决方案1】:

您需要将Ws2_32 库文件添加到您的项目中。 转到“项目构建选项”->“链接器设置”选项卡->单击“添加”按钮并写入Ws2_32



现在一切都应该正常了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2016-12-20
    相关资源
    最近更新 更多