【问题标题】:makefile error: sys/socket.h no such file or directory under Windowsmakefile error: sys/socket.h Windows下没有这样的文件或目录
【发布时间】:2014-03-16 04:23:50
【问题描述】:

我正在使用下面的makefile:

CC=g++

all: socket.exe

socket.exe: socket.o
    g++ socket.o -o socket.exe

socket.o: socket.cpp
    g++ -c socket.cpp

当我运行时让它显示错误:

socket.cpp: sys/socket.h: 没有这样的文件或目录。

如何解决?我在 Windows 上工作。

【问题讨论】:

  • 当你遇到这样的编译器错误时,显示socket.cpp 的代码比你的Makefile 更有意义,你不觉得吗?另外,您是从 Windows 运行g++ 吗? Cygwin,您的实际构建环境是什么?

标签: c


【解决方案1】:

<sys/socket.h> 用于 UNIX/Linux。

对于 Windows,您使用 <Winsock2.h>。您还需要链接到 Ws2_32.lib 并调用 WSAStartup 以使用 WinSock。

另见:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    相关资源
    最近更新 更多