Issue 36162: error: implicit declaration of function 'sendfile' is invalid in C99 (original) (raw)
Created on 2019-03-01 22:00 by muhzi, last changed 2022-04-11 14:59 by admin. This issue is now closed.
Messages (9)
Author: (muhzi)
Date: 2019-03-01 22:00
I encountered yet another issue with cross compilation on android, it so happens that these errors occur only when I cross compile for non 64-bit archs. i.e. I could cross compile just fine for arm64 & x86_64 but the 32-bit version of these archs produces the following error during compilation:
./Modules/posixmodule.c:8457:19: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration] ret = sendfile(out, in, NULL, count); ^ ./Modules/posixmodule.c:8457:19: warning: this function declaration is not a prototype [-Wstrict-prototypes] ./Modules/posixmodule.c:8470:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration] ret = sendfile(out, in, &offset, count); ^ ./Modules/posixmodule.c:9057:14: error: implicit declaration of function 'truncate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] result = truncate(path->narrow, length); ^ ./Modules/posixmodule.c:9057:14: note: did you mean 'ftruncate'? /home/muhzi/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/unistd.h:220:5: note: 'ftruncate' declared here int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12); ^ ./Modules/posixmodule.c:9057:14: warning: this function declaration is not a prototype [-Wstrict-prototypes] result = truncate(path->narrow, length);
I attached pyconfig.h for reference, it seems that the configuration step went fine. I checked that these missing functions are able to have their corresponding headers included. Also figured after misplacing some include lines in posixmodule.c that when the preprocessor includes Python.h it fails to include definitions from successively included headers.
Author: (muhzi)
Date: 2019-03-01 22:08
Using the latest NDK r19. Here is my compilation steps for arm:
export PATH="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH" export CC="armv7a-linux-androideabi16-clang" export CXX="$CC++"
export AR="arm-linux-androideabi-ar" export LD="arm-linux-androideabi-ld" export AS="arm-linux-androideabi-as" export STRIP="arm-linux-androideabi-strip" export RANLIB="arm-linux-androideabi-ranlib" export READELF="arm-linux-androideabi-readelf"
export CFLAGS="" export CXXFLAGS=$CFLAGS export LDFLAGS="-pie"
export CONFIG_SITE="config.site"
./configure --host=armv7a-linux-androideabi --build=x86_64-linux-gnu --disable-ipv6 make make altinstall DESTDIR=$INSTALL_DIR
Author: (muhzi)
Date: 2019-03-02 00:30
After some testing, it works and builds extensions OK for android arm with API>=21. fails on lower API versions (e.g. 16).
Author: Christian Heimes (christian.heimes) *
Date: 2019-03-02 11:36
The presence of sendfile and truncate is detected by configure. Your copy of configure defines HAVE_SENDFILE and HAVE_SYS_SENDFILE_H. Please check config.log and see why configure detects the functions.
Author: (muhzi)
Date: 2019-03-02 11:55
Yes it is detected by configure because they exist.
From config.log:
configure:11514: checking for truncate configure:11514: armv7a-linux-androideabi21-clang -o conftest -pie -march=armv7-a -Wl,--fix-cortex-a8 conftest.c -ldl >&5 configure:11514: $? = 0 configure:11514: result: yes
I can include the corresponding headers in a separate test file and call these missing methods and I get no compilation errors. But it seems they don't work in posixmodule.c and for some reason when #include <sys/sendfile.h> is put before #include "Python.h", the compiler doesn't give errors for those particular functions. I'm guessing this is an API level < 21 issue, it might have propagated from the configuration step (if any faults) but not sure. I use the same steps to compile this for API level 21 with no errors.
Author: (muhzi)
Date: 2019-03-02 12:07
err, wrong logs sorry...
configure:11514: checking for truncate configure:11514: armv7a-linux-androideabi16-clang -o conftest -pie -march=armv7-a -Wl,--fix-cortex-a8 conftest.c -ldl >&5 configure:11514: $? = 0 configure:11514: result: yes
configure:7954: checking sys/sendfile.h usability configure:7954: armv7a-linux-androideabi16-clang -c conftest.c >&5 configure:7954: $? = 0 configure:7954: result: yes configure:7954: checking sys/sendfile.h presence configure:7954: armv7a-linux-androideabi16-clang -E conftest.c configure:7954: $? = 0 configure:7954: result: yes configure:7954: checking for sys/sendfile.h configure:7954: result: yes
Author: (yan12125) *
Date: 2019-03-02 15:58
CPython requires several changes to build for Android < 21. There was an attempt in but it's abandoned.
Author: Inada Naoki (methane) *
Date: 2019-03-06 05:04
May I close this issue? I feel target SDK v21 is too old.
https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html
Author: (muhzi)
Date: 2019-03-06 08:48
Yeah, makes sense
History
Date
User
Action
Args
2022-04-11 14:59:11
admin
set
github: 80343
2019-03-06 10:13:13
methane
set
status: open -> closed
resolution: wont fix
stage: resolved
2019-03-06 08:48:44
muhzi
set
messages: +
2019-03-06 05:04:52
methane
set
nosy: + methane
messages: +
2019-03-02 15:58:41
yan12125
set
nosy: + yan12125
messages: +
2019-03-02 12:07:17
muhzi
set
messages: +
2019-03-02 11:55:55
muhzi
set
messages: +
2019-03-02 11:36:41
christian.heimes
set
nosy: + christian.heimes
messages: +
2019-03-02 00:30:59
muhzi
set
messages: +
2019-03-01 22:08:13
muhzi
set
messages: +
2019-03-01 22:00:18
muhzi
create