Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

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.

How to fix it? I am working on Windows.

like image 680
user3424840 Avatar asked Mar 16 '14 04:03

user3424840


1 Answers

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

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

See also:

  • socket function (MSDN)
  • Windows Socket Programming in C (Stack Overflow)
like image 195
Jonathon Reinhart Avatar answered Nov 12 '22 13:11

Jonathon Reinhart