我有一个C应用程序,我正在尝试编译Mac OS X 10.6.4:

$ uname -v
Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386

我的 gcc 如下:

$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)

我的 Makefile 如下:

CC=gcc
CFLAGS=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -O3 -Wformat -Wall -pedantic -std=gnu99

all: myApp
    rm -rf *~

myApp: myApp.o
    ${CC} ${CFLAGS} myApp.o -lbz2 -o myApp
    rm -rf *~

clean:
    rm -rf *.o myApp

问题是我的申请呼叫 fseeko64fopen64, ,并使用 off64_t 输入偏移。当我编译申请时,我会收到以下警告和错误:

$ make myApp
gcc -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -O3 -Wformat -Wall -pedantic -std=gnu99   -c -o myApp.o myApp.c
myApp.c: In function ‘extractData’:
myApp.c:119: warning: implicit declaration of function ‘fseeko64’
myApp.c:119: error: ‘off64_t’ undeclared (first use in this function)
myApp.c:119: error: (Each undeclared identifier is reported only once
myApp.c:119: error: for each function it appears in.)
myApp.c: In function ‘extractMetadata’:
myApp.c:305: warning: implicit declaration of function ‘fopen64’
myApp.c:305: warning: assignment makes pointer from integer without a cast

我的代码在Linux下没有错误构建。在达尔文(Darwin)下建造时,我可以对源代码进行什么更改?

有帮助吗?

解决方案

在darwin文件上,i/o默认为64位(至少为10.5),刚刚通过/usr/include找到了这一点:

sys/_types.h:typedef __int64_t  __darwin_off_t;

unistd.h:typedef __darwin_off_t     off_t;

因此,您需要做的就是

#ifdef __APPLE__
#  define off64_t off_t
#  define fopen64 fopen
...
#endif

其他提示

尽管这个问题有一个上投票的答案,但我认为解决方案有些误导。而不是修理一些东西 最好避免首先要避免修复它.

例如 fopen64 功能 GNU C库 文档说:

如果来源是与 _FILE_OFFSET_BITS == 64 在32位机器上 此功能可在名称下可用 fopen 因此透明地替换了旧界面.

您只能使用相同的功能 fopen 在支持64位I/O的系统上,您可以设置 _FILE_OFFSET_BITS=64 在32位上的标记完全不需要写重新定义。类型也是如此 off64_t VS. off_t.

当您必须处理第三方资源并在您自己的代码中使用标准功能时,将重新定义为案例。

FSEEKO和类似命令可在大量文件支持下使用,因此不需要FSEEKO64等 苹果人页面

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top