Skip to content

cmake: check fseeko after detecting HAVE_FILE_OFFSET_BITS - #13264

Closed
SirLynix wants to merge 2 commits into
curl:masterfrom
SirLynix:patch-1
Closed

cmake: check fseeko after detecting HAVE_FILE_OFFSET_BITS#13264
SirLynix wants to merge 2 commits into
curl:masterfrom
SirLynix:patch-1

Conversation

@SirLynix

@SirLynix SirLynix commented Apr 2, 2024

Copy link
Copy Markdown
Contributor

On Android, fseeko is defined as is (I omitted other functions for clarity):

/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
#if defined(__USE_FILE_OFFSET64)

#if __ANDROID_API__ >= 24
int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence) __RENAME(fseeko64) __INTRODUCED_IN(24);
#endif /* __ANDROID_API__ >= 24 */

#else
int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence);

#if __ANDROID_API__ >= 24
int fseeko64(FILE* _Nonnull __fp, off64_t __offset, int __whence) __INTRODUCED_IN(24);
#endif /* __ANDROID_API__ >= 24 */

#endif

Which means that on Android 32bits (armv7), fseeko is only available in 32bits mode, if __USE_FILE_OFFSET64 (_FILE_OFFSET_BITS=64) is set then fseeko is not available.

CMake detects fseeko as available because _FILE_OFFSET_BITS=64 is not yet defined when it tests for this function existence, but then it defines _FILE_OFFSET_BITS=64 which makes fseeko unavailable and fails compilation:

/home/runner/.xmake/cache/packages/2404/l/libcurl/8.6.0/source/lib/formdata.c:794:10: error: call to undeclared function 'fseeko'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  return fseeko(stream, (off_t)offset, whence);
         ^
/home/runner/.xmake/cache/packages/2404/l/libcurl/8.6.0/source/lib/formdata.c:794:10: note: did you mean 'fseek'?
/home/runner/work/xmake-repo/xmake-repo/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdio.h:215:5: note: 'fseek' declared here
int fseek(FILE* _Nonnull __fp, long __offset, int __whence);
    ^

A simple fix is to test for fseeko existence after testing HAVE_FILE_OFFSET_BITS and especially after

  set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")

tested here

Fix #12086 for good

Comment thread CMakeLists.txt Outdated
@vszakats vszakats changed the title CMake: check fseeko after detecting HAVE_FILE_OFFSET_BITS cmake: check fseeko after detecting HAVE_FILE_OFFSET_BITS Apr 2, 2024
SirLynix and others added 2 commits April 7, 2024 11:16
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
@bagder bagder closed this in 6b86471 Apr 8, 2024
@bagder

bagder commented Apr 8, 2024

Copy link
Copy Markdown
Member

Thanks!

@SirLynix
SirLynix deleted the patch-1 branch April 8, 2024 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

8.4.0 fails to build on cross-compiled android ARM

3 participants