sys / sendfile.h找不到GCC

时间:2011-11-24 05:44:09

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

我使用的是Mac OS 10.6.7,

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

它会抛出错误

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

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

4 个答案:

答案 0 :(得分:3)

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

OS X Developer Library表示您应该包含以下内容:

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

答案 1 :(得分:3)

根据Linux manual page

  

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

     

其他UNIX系统使用不同的语义和原型实现sendfile()。它不应该用在便携式程序中。

我不确定OSX,但似乎你必须自己去挖掘一下。

答案 2 :(得分:3)

sendfile()最终是一个内核功能而不是库或编译器,并引用linux手册页,“其他Unix系统实现了sendfile(),它具有不同的语义和原型。它不应该用在便携式程序中。”< / p>

这里似乎有一个OSX sendfile()的联机帮助页:https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/sendfile.2.html

事实上,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>

答案 3 :(得分:2)

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

相关问题