c++ - 为 Android NDK 编译 Boost 库的子集

标签 c++ boost android-ndk boost-spirit

我的 Android 应用程序需要一个 boost 库,所以我设法编译了其中的大部分。但是当我尝试编译文件系统组件时,出现以下错误消息。

gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-android4.4.3/release/link-static/runtime-link-static/threading-multi/v2/src/v2_operations.o
libs\filesystem\v2\src\v2_operations.cpp:62:30: 
     error: sys/statvfs.h: No such file or directory

我理解这是因为Android NDK的gcc没有statvfs.h相关的部分。

我想知道的是,boost-spirit 是否需要文件系统组件?当然,如果您知道如何解决该错误,那就完美了。

最佳答案

解决编译错误

我还没有用 Boost Filesystem 尝试过这个,但它可能会起作用:

#ifndef ANDROID
  #include <sys/statvfs.h>
#else
  #include <sys/vfs.h>
  #define statvfs statfs
#endif

如果 Boost Spirit 需要 Boost 文件系统

根据 boost manual它是一个只有标题的模块。 :)

为什么android没有statvfs?

根据其manpage , statvfs 是针对 POSIX 的,但是 Linux(Android 是基于 Linux 的)不服从它。以下引号适用:

Some systems only have <sys/vfs.h>, other systems also have <sys/statfs.h>, where the former includes the latter. So it seems including the former is the best choice.


Solaris, Irix and POSIX have a system call statvfs(2) that returns a struct statvfs (defined in <sys/statvfs.h>) containing an unsigned long f_fsid. Linux, SunOS, HP-UX, 4.4BSD have a system call statfs() that returns a struct statfs (defined in <sys/vfs.h>) containing a fsid_t f_fsid, where fsid_t is defined as struct { int val2; }. The same holds for FreeBSD, except that it uses the include file <sys/mount.h>.

关于c++ - 为 Android NDK 编译 Boost 库的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8275203/

相关文章:

c++ - 将实用程序放在与其使用的类型相同的 namespace 中?

c++ - 实现全局范围数据的最佳方式

c++ - 遍历 Boost multi_array View

c++ - 带有 boost::shared_ptr 的空指针?

android - 配置文件如何找到正确的交叉编译工具?

android - 构建GDB android

c++ - 将 "value type"作为默认的第二个参数传递给模板

c++ - 如何访问加载图像的各个 R/G/B 组件(较新的 C++ API)

c++ - 如何确保boost安装成功?

android - 无法在设备上运行 Android NDK 应用程序