MingW上编译WinSocket程序undefined reference to `WSAStartup@8’报错的解决办法

  • Post author:
  • Post category:其他



在Mingw stdio上编译Windows Socket程序经常出现这样的错误


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′


解决办法是


进入Project->Settings…->Link,在Extra linking options:一栏中加上-lwsock32



版权声明:本文为u011348999原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。