C语言 makefile 错误:sys/socket.h 在 Windows 下没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22432910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:54:24  来源:igfitidea点击:

makefile error: sys/socket.h no such file or directory under Windows

c

提问by user3424840

I am using following makefile below:

我在下面使用以下生成文件:

CC=g++

all: socket.exe

socket.exe: socket.o
    g++ socket.o -o socket.exe

socket.o: socket.cpp
    g++ -c socket.cpp

When I run make it show error:

当我运行时让它显示错误:

socket.cpp: sys/socket.h: no such file or directory.

socket.cpp: sys/socket.h: 没有这样的文件或目录。

How to fix it? I am working on Windows.

如何解决?我在 Windows 上工作。

回答by Jonathon Reinhart

<sys/socket.h>is for UNIX/Linux.

<sys/socket.h>适用于 UNIX/Linux。

For windows, you use <Winsock2.h>. You'll also need to link against Ws2_32.liband call WSAStartupto use WinSock.

对于 Windows,您使用<Winsock2.h>. 您还需要链接Ws2_32.lib并调用WSAStartup以使用 WinSock。

See also:

也可以看看: