'sizeof(off_t) != 8' when compiling libfuse for android

时间:2017-07-17 15:30:44

标签: android c android-ndk fuse

I'm trying to compile libfuse with NDK, my environment:

Win10(64bit) + NDK(r14b,64bit) + libfuse(3.1.0)

Error occurs in fuse_common.h, it checks size of off_t:

$ ndk-build
[armeabi-v7a] Compile thumb  : fuse <= buffer.c
In file included from jni/../../libfuse/lib/buffer.c:15:
In file included from jni/../../libfuse/lib/fuse_i.h:9:
In file included from jni/../../libfuse/include\fuse.h:19:
jni/../../libfuse/include/fuse_common.h:745:13: error: bit-field
      '_fuse_off_t_must_be_64bit' has negative width (-1)
        { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
                   ^
1 error generated.
make: *** [obj/local/armeabi-v7a/objs/fuse/__/__/libfuse/lib/buffer.o] Error 1

here's the check in fuse_common.h:

struct _fuse_off_t_must_be_64bit_dummy_struct \
    { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };

I searched on google, there's _FILE_OFFSET_BITS=64 definition, which can be used to change the size of off_t, I have this defined my 'Android.mk' file:

LOCAL_CFLAGS := \
    ....
    -D_FILE_OFFSET_BITS=64 \
    ....

And even add this line at the beginning of fuse_common.h

#define _FILE_OFFSET_BITS 64

Still not working, how to fix it?

2 个答案:

答案 0 :(得分:4)

更新至NDK r15c。 _FILE_OFFSET_BITS=64从那里开始工作。

请注意,大多数off64_t系统调用直到android-21才可用。如果您的minSdkVersion设置在_FILE_OFFSET_BITS=64之下并使用<text> attribute x: Expected length, "NaN".,则许多功能将无法使用。

答案 1 :(得分:0)

注意提供的解决方案非常类似于解决方法,请参阅@ Dan的答案,了解获得64位off_t的可靠和官方方法。

在Android off_t上总是32位长度,并且没有控制其大小的预处理器宏。 (虽然它只适用于NDK开发,因为现代仿生允许在编译时配置off_t大小。因此,您无法直接编译库。

但我想有办法解决它。 Android NDK提供非POSIX扩展类型 - off64_t,并且它还提供了一组互补的库函数,而不是off_t。它们以64后缀区分,即lseek64()mmap64()。因此,为了使工作正常,您可以尝试将全局配置标头添加到项目中:

/* let off_t to be a 64-bit length */
typedef off64_t off_t;

/* use appropriate versions of system functions */
/* list here only functions that have off_t parameters and are used by your library */
#define mmap mmap64
#define lseek lseek64

当然要记住,编译后的代码现在与*64()函数相关联,而不是常规函数,任何公共接口都需要off64_t而不是off_t