linux中的套接字头在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4023343/
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-08-04 23:47:26  来源:igfitidea点击:

where is socket header in linux

c++linux

提问by Dzung Nguyen

I compile my simple prog with #include <sys/socket.h>but there's none of this file. Where is it, I just start coding in linux and I have no idea where is it . Or do we need to download it online .

我编译了我的简单编,#include <sys/socket.h>但没有这个文件。它在哪里,我刚开始在 linux 中编码,我不知道它在哪里。或者我们需要在线下载它。

采纳答案by Peter G.

In case you have installed manual pages, the first stop should be man socket.

如果您安装了手册页,第一站应该是man socket

Without manual pages you could call

没有手册页,您可以调用

find /usr/include -name socket.h

which outputs

哪个输出

/usr/include/asm/socket.h
/usr/include/sys/socket.h
/usr/include/bits/socket.h
/usr/include/linux/socket.h

on my system, the one to include is sys/socket.h.

在我的系统上,要包含的文件是sys/socket.h.

Also see the Single UNIX Specification.

另请参阅单一 UNIX 规范

回答by Chris J

It should be #include <sys/socket.h>. You may also need to include sys/types.h.

应该是#include <sys/socket.h>。您可能还需要包括sys/types.h.

But if that's failing, can you give a short snippet of source, including what files you're #include'ing and how, and what error message(s) you're getting?

但是,如果失败了,您能否提供一个简短的源代码片段,包括您正在#include'ing 的文件和方式,以及您收到的错误消息?

回答by mouviciel

man socket

should give you the answer.

应该给你答案。

回答by B?ови?

You need to

你需要

#include <sys/socket.h>

See this :

看到这个:

http://linux.die.net/man/7/socket

http://linux.die.net/man/7/socket

回答by coanor

On a fresh Linux, for example, Ubuntu X86-64, while there is no gcc installed, there is no socket.hheaders, while installed gcc, you can findit under /usr/include, for me, the output is:

在新的Linux上,例如Ubuntu X86-64,虽然没有安装gcc,但没有socket.h头文件,安装了gcc后,你可以find在 下/usr/include,对我来说,输出是:

$ find /usr/include/ -name socket.h
/usr/include/asm-generic/socket.h
/usr/include/x86_64-linux-gnu/asm/socket.h
/usr/include/x86_64-linux-gnu/bits/socket.h
/usr/include/x86_64-linux-gnu/sys/socket.h
/usr/include/linux/socket.h