【问题标题】:sys/sendfile.h not found GCCsys/sendfile.h 未找到 GCC
【发布时间】:2012-01-05 08:46:08
【问题描述】:

我使用的是 Mac OS 10.6.7,

gcc 编译器在我购买 Mac 时已经存在。 但是当我尝试包含 sys/sendfile.h #include<sys/sendfile.h>

会报错

sys/sendfile.h: No such file or directory.

但是这个程序在 ubuntu GCC 编译器中可以正常工作。知道如何解决这个问题吗?

【问题讨论】:

    标签: c++ c networking gcc osx-snow-leopard


    【解决方案1】:

    sendfile() 最终是一种内核功能,而不是库或编译器功能,并且引用 linux 手册页,“其他 Unix 系统实现 sendfile() 具有不同的语义和原型。它不应该在可移植程序中使用。”

    这里曾经有一个指向适用的 OSX/Darwin 手册页的 sendfile 的链接,但 Apple 一直在移动他们的文档,所以你必须自己找到它。

    确实,linux 手册页警告是准确的 - 原型不同:

    OSX:

    int sendfile(int fd, int s, off_t offset, off_t *len, struct sf_hdtr *hdtr, int flags);
    

    Linux:

    ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
    

    所以你需要重写一些工作。

    osx 包含在该手册页上,但为了完整性:

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/uio.h>
    

    【讨论】:

    • 链接已损坏。
    【解决方案2】:

    根据Linuxmanual page

    在 POSIX.1-2001 或其他标准中未指定。

    其他 UNIX 系统使用不同的语义和原型实现 sendfile()。不应在可移植程序中使用它。

    我不确定 OSX,但似乎你必须自己挖掘一下才能找到它。

    【讨论】:

    • 是的,你是对的。我摆脱了头文件丢失错误。但是 sendfile 的原型不同。
    【解决方案3】:

    您在寻找sendfile(2) 吗?如果是这样,它不在sys/sendfile.h

    OS X Developer Library 声明您应该包括以下内容:

     #include <sys/types.h>
     #include <sys/socket.h>
     #include <sys/uio.h>
    

    【讨论】:

    • 不知道为什么 OP 正在寻找 sys/sendfile.h,而文档中没有提到这一点。
    • @Huw 因为那是它在 linux 上的位置,并且程序正在从 linux 移植。但不仅需要更改包含,因为函数本身采用与 linux 版本不同的参数。
    【解决方案4】:

    在 OSX 上,发送文件是在 socket.h 中定义的。所以你需要包含 socket.h 而不是 sys/sendfile.h

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 2014-05-01
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多