gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:39:14 24 4
gpt4 key购买 nike

我有以下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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com