Where is the socket header in Linux

I will compile my simple program with #include <sys/socket.h> , but there is not a single file. Where is it, I'm just starting coding on Linux, and I have no idea where it is. Or we need to download it online.

+6
c ++ linux
source share
5 answers

If you installed the manual pages, the first stop should be a man socket .

Without man pages you can 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 that should be enabled is sys/socket.h .

See also UNIX Unified Specification .

+17
source share
 man socket 

should give you an answer.

+2
source share

On new Linux, for example, Ubuntu X86-64, while there is no gcc installed, there are no socket.h headers, whereas gcc, you can find 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 
+2
source share

You need

 #include <sys/socket.h> 

See this:

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

+1
source share

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

But if this fails, can you give a short fragment of the source, including which files you include and how, and what error messages you receive?

-one
source share

All Articles