11

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.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
user3424840
  • 207
  • 2
  • 3
  • 8
  • 1
    When you have a compiler error like this, it makes far more sense to show the code for `socket.cpp` than your `Makefile`, don't you think? Also, you're running `g++` from Windows? What is your *actual* build environment, Cygwin? – Jonathon Reinhart Mar 16 '14 at 04:31

1 Answers1

21

<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:

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328