Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error with Android NDK r15c #942

Open
BillPyne opened this issue Aug 18, 2017 · 16 comments
Open

Build error with Android NDK r15c #942

BillPyne opened this issue Aug 18, 2017 · 16 comments

Comments

@BillPyne
Copy link

While trying to build libarchive 3.3.2 with Android NDK r15c on OS X 10.12.6, I encounter a compile issue with statvfs. NDK 15 uses the new "unified header files" by default which essentially means all header files are present from the NDK regardless of the minimum API version being compiled for.

In my case, the minimum version is API 15 (not to be confused with the NDK version) where statvfs is not available at runtime. Most of the definitions inside statvfs.h are protected with API level checks, but the header file is still visible to libarchive's configure script. Hence, this causes the later compile error since the configure script just checks for the presence of statsvfs.h.

@kientzle
Copy link
Contributor

  1. What exactly is the error?

  2. What is the value of HAVE_STATVFS in your generated config.h?

The configure script definitely does test for the presence of the statvfs function (not just the header). Those checks will set HAVE_STATVFS in config.h only if the function is available. I just skimmed through the source and it looks like all our uses of statvfs are protected by HAVE_STATVFS checks. We might have missed a spot (which should be obvious from the error), or there could be a configuration issue that's causing it to believe the function is available (which would result in HAVE_STATVFS being set when it shouldn't). There are other possibilities, but the answers to the two questions above should help us narrow it down.

@BillPyne
Copy link
Author

BillPyne commented Aug 18, 2017

My apologies! I should have included more specifics especially since I made a mistake. I mixed some of the statvfs and statfs in my head as I skimmed the code.

  1. The exact error is:
libarchive/archive_read_disk_posix.c:1803:10: error: no member named 'f_flag' in 'struct statfs'; did you mean 'f_flags'?
         if (sfs.f_flag & ST_NOATIME)
                 ^~~~~~
                 f_flags
{some path}/libarchive/android_toolchain-x86-plat-15/bin/../sysroot/usr/include/sys/vfs.h:108:17: note: 'f_flags' declared here
struct statfs { __STATFS64_BODY };
                ^
{some path}/libarchive/android_toolchain-x86-plat-15/bin/../sysroot/usr/include/sys/vfs.h:103:12: note: expanded from macro '__STATFS64_BODY'
  uint32_t f_flags; \
           ^
1 error generated.
  1. The values of HAVE_STATVFS and HAVE_STATFS are:
/* Define to 1 if you have the `statfs' function. */
#define HAVE_STATFS 1

/* Define to 1 if you have the `statvfs' function. */
/* #undef HAVE_STATVFS */

Out of curiosity I removed statvfs.h from the NDK, and libarchive compiles in that form. I see that ST_NOATIME is defined in the NDK's statvfs.h.

Hopefully this is much more helpful!

@DanAlbert
Copy link

That looks like a bug in the code (presumably the !HAVE_STATVFS case doesn't get exercised often). Both Android and glibc agree that the statfs name is f_flags, not f_flag. https://github.com/libarchive/libarchive/blob/master/libarchive/archive_read_disk_posix.c#L1800

@kientzle
Copy link
Contributor

Looks like NetBSD and FreeBSD also use f_flags. Care to send us a PR making that change?

@DanAlbert
Copy link

How do I build this for Android? The Android.mk files that are in contrib/android is for the platform, not the NDK, and cmake gives me:

In file included from /work/src/libarchive/libarchive/archive_match.c:40:
../libarchive/archive.h:101:10: fatal error: 'android_lf.h' file not found
#include "android_lf.h"
         ^~~~~~~~~~~~~~
1 error generated.

I could send a patch to do this either way, but I'd prefer to check that it works first...

@BillPyne
Copy link
Author

We went the standalone toolchain route with the NDK and use make, but our script is fairly old. In other words, if there is a newer, preferred way to build libarchive, we are not doing it.

@DanAlbert
Copy link

Ah, okay. Looking at the issues that come up with cmake, I think they can be fixed pretty easily. Unless one of you beats me to it, I can put a patch together on Monday.

@DanAlbert
Copy link

@kientzle: what's your expected minimum supported Android version? libarchive uses things like mbtowc and wctomb that weren't available until android-21 (Lollipop).

@DanAlbert
Copy link

Also, what's the oldest NDK you want to support? If you're only supporting modern NDKs that have non-ancient headers the fix for building with cmake is to just delete some of the android specific hacks, but if you want to keep supporting pre-r15 then you'll need to keep the hacks around.

@Blocked
Copy link

Blocked commented Oct 15, 2021

@DanAlbert Could you tell me how to include this file during a cmake build? I'm trying to build opencv in android and this error keeps coming up. There's a patch for this in termux - https://github.com/termux/termux-packages/blob/27afd9e6656803aa3b4c96bdb4eef2add7a57337/packages/libarchive/archive.h.patch

But I don't know how to make cmake use the patched library. Cmake seems to download and use this one instead.

Any help?

@zgbilltalent
Copy link

How to compile it ?

@asthagarg2428
Copy link

asthagarg2428 commented Mar 21, 2022

@zgbilltalent you got any answer on using it in Android project?

@zgbilltalent
Copy link

Which answer?No one told me,I have solved it

@zgbilltalent
Copy link

@zgbilltalent you got any answer on using it in Android project?

Which answer?No one told me,I have solved it

@asthagarg2428
Copy link

@zgbilltalent you got any answer on using it in Android project?

Which answer?No one told me,I have solved it

I'm in same position as you were, would like take your help.
Can you please your email id so that we can connect?

@zgbilltalent
Copy link

@zgbilltalent you got any answer on using it in Android project?

290971614@qq.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants