Build error because of "implicit declaration of function 'sendfile'"

1,375 views
Skip to first unread message

Marc Richter

unread,
Dec 5, 2020, 3:15:00 AM12/5/20
to Kivy users support
Subj: Build error because of "implicit declaration of function 'sendfile'"

Hi everyone,

I'm a first-time user of Kivy and Buildozer and my goal is to build a Python App for Android. I created an Android AVD Orio (8.1, API 27) emulator for x86.
Next, I created an empty folder named `buildozer`, switched to it and executed `buildozer init`, which created a file named buildozer.spec. In that file, I only changed `android.arch`from `armeabi-v7a` to `x86` and left the rest as is.

I then took a code example from https://realpython.com/mobile-app-kivy-python/#creating-a-kivy-application and saved that as `main.py` in the `buildozer/` directory.
On the commandline, I changed into that buildozer/ directory and executed `buildozer -v android debug` with the virtualenv activated.
This results in this:


gcc -c -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy1/buildozer/.buildozer/android/platform/build-x86/build/other_builds/hostpython3/desktop/hostpython3/Include/internal -IObjects -IInclude -IPython -I. -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy1/buildozer/.buildozer/android/platform/build-x86/build/other_builds/hostpython3/desktop/hostpython3/Include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -DPy_BUILD_CORE -o Programs/_testembed.o /Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy1/buildozer/.buildozer/android/platform/build-x86/build/other_builds/hostpython3/desktop/hostpython3/Programs/_testembed.c
sed -e "s,@EXENAME@,/usr/local/bin/python3.8," < /Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy1/buildozer/.buildozer/android/platform/build-x86/build/other_builds/hostpython3/desktop/hostpython3/Misc/python-config.in >python-config.py
/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy1/buildozer/.buildozer/android/platform/build-x86/build/other_builds/hostpython3/desktop/hostpython3/Modules/posixmodule.c:9084:15: error:
implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ret = sendfile(in, out, offset, &sbytes, &sf, flags);
^
LC_ALL=C sed -e 's,\$(\([A-Za-z0-9_]*\)),\$\{\1\},g' < Misc/python-config.sh >python-config
1 error generated.
make: *** [Modules/posixmodule.o] Error 1


Since I'm a first-time user of Kivy and Buildozer, I do not have any clue what's going on.
Can someone please provide me some jump start?

Best regards,
Marc Richter

planckp...@gmail.com

unread,
Dec 5, 2020, 12:27:24 PM12/5/20
to Kivy users support
No clue here either.

It looks like an install issue, but I really don't know, check all the install steps were followed:

Marc Richter

unread,
Dec 12, 2020, 8:45:24 AM12/12/20
to Kivy users support
I once more followed all guides to install Kivy using 
  • Homebrew Python 3.8.6
  • a virtualenv inside the project folder (was a pipenv using Python 3.8.6 installed by pyenv before)
  • `kivy[full]`, `cython` and `kivy_examples` using pip
Also, I followed these guides to setup my MacOSX Environment:

Heading back to my Real Python article at https://realpython.com/mobile-app-kivy-python/#creating-a-kivy-application, the full code example of the calculator also runs fine in my MacOSX environment. That's 3 code samples, that are satisfied with my Kivy environment setup in MacOSX.

The next step is to follow the `buildozer` - section to build an Android package out of the calculator app.
I did this step-by-step wise as follows:
  1. mkdir buildozer && cd buildozer
  2. buildozer init
  3. cp ../calculator.py ./main.py
  4. buildozer -v android debug
Unce more, with this result:

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration  -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include/internal -IObjects -IInclude -IPython -I. -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include  -DPy_BUILD_CORE_BUILTIN  -DPy_BUILD_CORE_BUILTIN -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include/internal -c /Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_functoolsmodule.c -o Modules/_functoolsmodule.o
/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/posixmodule.c:9084:15: error: 
      implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration  -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include/internal -IObjects -IInclude -IPython -I. -I/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include  -DPy_BUILD_CORE_BUILTIN  -c /Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_operator.c -o Modules/_operator.o
1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.


  STDERR:

# Command failed: /Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/venv/bin/python -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=python3,kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21
# ENVIRONMENT:
#     SHELL = '/usr/local/bin/bash'
#     PYENV_SHELL = 'bash'
#     XPC_FLAGS = '0x0'
#     CONDA_EXE = '/usr/local/Caskroom/miniconda/base/bin/conda'
#     _CE_M = ''
#     TERMINAL_EMULATOR = 'JetBrains-JediTerm'
#     HISTSIZE = '-1'
#     __CFBundleIdentifier = 'com.jetbrains.pycharm'
#     SSH_AUTH_SOCK = '/private/tmp/com.apple.launchd.3wZrQQagRo/Listeners'
#     BLUE = '\\033[01;34m'
#     PWD = '/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer'
#     PYENV_VIRTUALENV_INIT = '1'
#     LOGNAME = 'marcrichter'
#     CONDA_PREFIX = '/usr/local/Caskroom/miniconda/base'
#     RESET = '\\033[00m'
#     COMMAND_MODE = 'unix2003'
#     LDFLAGS = '-L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib'
#     HOME = '/Users/marcrichter'
#     COLUMNS = '193'
#     VIRTUAL_ENV = '/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/venv'
#     CONDA_PROMPT_MODIFIER = '(base) '
#     TMPDIR = '/var/folders/fn/vyh4bf7n1l73k4pfypqdp2tm0000gp/T/'
#     CPPFLAGS = '-I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include'
#     ANDROID_AVD_HOME = '/Users/marcrichter/.android/avd'
#     ANDROID_HOME = '/Users/marcrichter/Library/Android/sdk'
#     TERM = 'xterm-256color'
#     _CE_CONDA = ''
#     USER = 'marcrichter'
#     OBJC_DISABLE_INITIALIZE_FORK_SAFETY = 'YES'
#     CONDA_SHLVL = '1'
#     DISPLAY = '/private/tmp/com.apple.launchd.MEle43ZjeF/org.macosforge.xquartz:0'
#     SHLVL = '1'
#     ANDROID_SDK_ROOT = '/Users/marcrichter/Library/Android/sdk'
#     XPC_SERVICE_NAME = '0'
#     CONDA_PYTHON_EXE = '/usr/local/Caskroom/miniconda/base/bin/python'
#     LC_CTYPE = 'en_DE.UTF-8'
#     RED = '\\033[1;31m'
#     PS1 = ('(venv) (base) [last: ${timer_show}] [exit: `nonzero_return`] '
 '\\033[01;34m\\u\\033[00m \\D{%H:%M:%S (%Z) %a '
 '%Y-%m-%d}\\n\\033[01;34m`pwd`\\033[00m\\n\\W \\$ ')
#     CONDA_DEFAULT_ENV = 'base'
#     LC_ALL = 'en_US.utf-8'
#     PATH = ('/Users/marcrichter/.buildozer/android/platform/apache-ant-1.9.4/bin:/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/venv/bin:/usr/local/opt/openssl@1.1/bin:/usr/local/opt/curl/bin:/usr/local/opt/sqlite/bin:/usr/local/Caskroom/miniconda/base/bin:/usr/local/Caskroom/miniconda/base/condabin:/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/Users/marcrichter/.pyenv/plugins/pyenv-virtualenv/shims:/Users/marcrichter/.pyenv/shims:/Users/marcrichter/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/usr/local/share/dotnet:/usr/local/munki:/opt/X11/bin:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin '
 'Workbooks.app/Contents/SharedSupport/path-bin')
#     GREEN = '\\033[01;32m'
#     HISTFILESIZE = '-1'
#     OLDPWD = '/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2'
#     __CF_USER_TEXT_ENCODING = '0x1F6:0x0:0x0'
#     _ = '/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/venv/bin/buildozer'
#     PACKAGES_PATH = '/Users/marcrichter/.buildozer/android/packages'
#     ANDROIDSDK = '/Users/marcrichter/.buildozer/android/platform/android-sdk'
#     ANDROIDNDK = '/Users/marcrichter/.buildozer/android/platform/android-ndk-r19c'
#     ANDROIDAPI = '27'
#     ANDROIDMINAPI = '21'
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2
(venv) (base) [last: 190s] [exit: 1] marcrichter 14:39:30 (CET) Sat 2020-12-12
/Users/marcrichter/ownCloud/Dokumente/Entwicklung/Android/kivy2/buildozer
buildozer $



I'm out of ideas what else in this quite basic setup I could possibly do different.

Any ideas from a more kivy advanced fella?

Best regards,
Marc Richter

Marc Richter

unread,
Dec 12, 2020, 2:28:34 PM12/12/20
to Kivy users support
Found it!

It is neither an issue in buildozer, nor kivy. It is a Python compilation issue that happens in conjunction with macOS Big Sur; see https://github.com/pyenv/pyenv/issues/1737 for details.

I was able to work around this by doing the following (I did it with python-for-android, but should work similarly with buildozer):
  1. run `p4a apk` (or `buildozer -v android debug`) and wait until the shown error occurs.
  2. Apply the patch https://github.com/python/cpython/commit/8ea6353.patch/?full_index\=1 to the source folder where p4a / buildozer compile Python in so that `configure` and `configure.ac` files are changed; should be:
    1. p4a: ~/.python-for-android/build/other_builds/hostpython3/desktop/hostpython3/
    2. buildozer: ${YOUR_BUILD_DIR}/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/
That should be it!
I now have a different problem, but this should be the fix for the initial problem.
Now I face:

checking for arm-linux-androideabi-gcc... /Users/marcrichter/.buildozer/android/platform/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang
checking whether the C compiler works... no
configure: error: in `/Users/marcrichter/.python-for-android/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/android-build':
configure: error: C compiler cannot create executables

But that's another story :)


Best regards,
Marc Richter


Message has been deleted

Leo BigSure

unread,
Dec 15, 2020, 12:59:01 AM12/15/20
to Kivy users support
Hi!

I opened a issues in buildozer repo:
Message has been deleted

Raghav

unread,
Jan 4, 2021, 3:26:08 AM1/4/21
to Kivy users support
Thank you for the solution! It worked flawlessly.
For your next error with "configure: error: C compiler cannot create executables", try enabling altering your security setting in mac to enable it to "Allow apps from anywhere". Refer this link for same: https://www.macworld.co.uk/how-to/mac-app-unidentified-developer-3669596/

Although, after passing through this error, now I'm stuck at a new error that reads:
sh.ErrorReturnCode_1:


  RAN
: /Users/raghav/.python-for-android/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 -m venv venv


  STDOUT
:
Error: Command '['/Users/raghav/.python-for-android/build/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.




  STDERR
:

Could you help me solve this?
Reply all
Reply to author
Forward
0 new messages