c - netdb.h : No such file or directory while trying to run a socket program (in C language) on windows

标签 c sockets networking compiler-errors winsock

我有以下C代码,需要运行它。但是我在使用的库中总是出现以下错误。我尝试下载MinGW,并将其路径添加到环境变量中,但是仍然存在相同的问题。

[Error] netdb.h: No such file or directory


我正在尝试在Windows上运行我的代码。这是一个C语言Socket程序。
这些库是:
#include <stdio.h> 
#include <netdb.h> 
#include <netinet/in.h> 
#include <stdlib.h> 
#include <string.h> 
#include <sys/socket.h> 
#include <sys/types.h> 
#define MAX 80 
#define PORT 8080 
#define SA struct sockaddr 
另一个问题,如果我想在笔记本电脑上将套接字作为客户端和服务器(Windows)运行,该怎么办?

最佳答案

这些时候我也做同样的事情。
我也有问题。如果在Windows上运行脚本,则必须安装正确的头文件。我用...

#ifdef _WIN32
//For Windows
int betriebssystem = 1;
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <ws2def.h>
#pragma comment(lib, "Ws2_32.lib")
#include <windows.h>
#include <io.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
int betriebssystem = 2;
#endif
尝试运行它。也许您必须链接“ws2_32”的库。

关于c - netdb.h : No such file or directory while trying to run a socket program (in C language) on windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65206157/

相关文章:

c - stm32 的系统工作台 : fatal error . .. 没有那个文件或目录

c - 处理具有相同主编号但唯一次编号的多个设备文件

iOS全时后台服务-基于位置追踪

java - getNetworkPrefixLength() 返回奇怪的子网掩码

c - 我尝试添加链接列表时遇到问题,但调试器说无法访问临时内存

c - 初始化 float 组 C

java - Arduino Client通过Sockets向Java Server发送数据

c - 通过使套接字事件驱动使udp套接字成为非阻塞的

sockets - SO_REUSEADDR 和 AF_UNIX

java - 使用 JAVA 配置 SNMP 代理和管理器