【发布时间】:2014-04-29 12:45:24
【问题描述】:
我在 Eclipse 的 Windows 机器上用 C 语言创建了一个经典的客户端服务器程序。代码本身不会产生任何错误。我得到的唯一错误是关于图书馆的。我已包含以下库:
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
但是当我尝试构建项目时出现错误:
error "ws2tcpip.h is not compatible with winsock.h. Include winsock2.h instead".
唯一的问题是我没有包含winsock.h,只包含了winsock2.h,就像他们指定的那样。
我该如何解决这个问题?
更新
我现在按以下顺序定义了库:
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
但现在我得到更多错误:
undefined reference to `socket@12'
undefined reference to `gethostbyname@4'
undefined reference to `connect@12'
undefined reference to `htons@4'
undefined reference to `WSACleanup@0'
undefined reference to `closesocket@4'
undefined reference to `WSACleanup@0'
undefined reference to `WSAStartup@8'
更新 2
我认为这个警告可能与我仍然不断收到的错误有关:
ignoring #pragma comment [-Wunknown-pragmas]
【问题讨论】:
标签: c windows sockets libraries