开发者

where is socket header in linux

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 .


In case you have installed manual pages, the first stop should be 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 .

Also see the Single UNIX Specification.


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

$ 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


man socket

should give you the answer.


You need to

#include <sys/socket.h>

See this :

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


It should be #include <sys/socket.h>. You may also need to include 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜