Tensorflow android cmake build can't find python - android

I'm trying to build tflite in my android project using cmake. I've managed to work this approach on the linux (debian) version of the same project.When compiling the arm64 version I followed the official docs When I open android studio and press build/run on top right corner, I get this error:
In file included from /home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite/python/interpreter_wrapper/numpy.cc:17:
In file included from /home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite/python/interpreter_wrapper/numpy.h:49:
In file included from /usr/include/python3.9/Python.h:8:
/usr/include/python3.9/pyconfig.h:9:12: fatal error: 'aarch64-linux-gnu/python3.9/pyconfig.h' file not found
When I open the file that throws the error I see the this line indicating that it's searching for it in the system:
#include <aarch64-linux-gnu/python3.9/pyconfig.h>
I ran sudo find / -name "aarch64-linux-gnu" to see whether I have that file or not and indeed I have this file installed:
user#debian:~$ sudo find / -name "aarch64-linux-gnu"
...
/home/user/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/aarch64-linux-gnu/include/c++/8.3.0/aarch64-linux-gnu
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/usr/lib/mesa-diverted/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu
/usr/share/gdb/auto-load/lib/aarch64-linux-gnu
/usr/share/gdb/auto-load/usr/lib/aarch64-linux-gnu
/usr/include/finclude/aarch64-linux-gnu
/usr/include/aarch64-linux-gnu
I located inside /usr/include/aarch64-linux-gnu and indeed saw /python3.9/pyconfig.h.
The way I did everything is this:
sudo git clone https://github.com/tensorflow/tensorflow.git /home/user/Desktop/official_stuff/tensorflow_src
curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz
mkdir -p ${HOME}/toolchains
tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C ${HOME}/toolchains
ARMCC_PREFIX=${HOME}/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
ARMCC_FLAGS="-funsafe-math-optimizations"
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
-DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
-DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
-DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
../tensorflow/lite/
And then I needed to ran dpkg --add-architecture arm64, apt-get update, sudo apt install libpython3-dev:arm64
I simply clicked build ran after connecting my android device. It compiled for a while and then throw the error.
Here is the cmake snippet I ran that contains my tflite inclusion:
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project" )
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"/home/user/Desktop/official_stuff/tensorflow_src" ABSOLUTE)
endif()
add_library(tensorflowlite SHARED IMPORTED)
add_subdirectory(
"/home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL
)
...
target_link_libraries(
my_proj
tensorflow-lite
)
How can I fix this issue?
Note: I got to this point following a series of questions which all resolved:
An undefined error.
Question regarding android build.
More details about how I built everything can be found here. I'm on debian 11.

Related

How to generate libpjsua2.so for x86 abi in jnilibs

I want to test the app with android 10 in emulator.So for that I only have "armeabi", "armeabi-v7a","arm64-v8a" in jnilibs. But running app with android 10 device(Emulator), requires x86 abi. So for that first I have downloaded ndk for x86.And the second thing is I want to generate libpjsua2.so for x86 abi.
I am using pjsip library.
I have referred to https://trac.pjsip.org/repos/wiki/Getting-Started/Android. What I have tried is,
1) Downloaded latest pjsip version and extracted in folder.
2) Followed the steps given in pjsip website as below,
$ cd /path/to/your/pjsip/dir
$ export ANDROID_NDK_ROOT=/path_to_android_ndk_dir
$ ./configure-android
$ make dep && make clean && make
$ cd /path/to/your/pjsip/dir
$ make clean
# cleanup pjsua sample app
$ cd pjsip-apps/src/pjsua/android/jni
$ make clean
# also cleanup pjsua2 sample app (SWIG)
$ cd /path/to/your/pjsip/dir
$ cd pjsip-apps/src/swig
$ make clean
$ cd pjsip-apps/src/swig
$ make clean
TARGET_ABI=x86 ./configure-android --use-ndk-cflags
Got error when reached above code,
LDFLAGS = --sysroot= -L/libs/x86/
LIBS = -lgnustl_static -lc -lgcc -ldl
AR = /home/Android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
RANLIB = /home/Android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
TARGET_HOST = llvm-linux-android
TARGET_ABI = x86
checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `llvm-linux-android': machine `llvm' not recognized
aconfigure: error: /bin/sh ./config.sub llvm-linux-android failed
In my pjsip2.7 folder I found a folder named llvm but that is a empty folder. I doesn't know What is that. I am using cent os 7. Why I am getting this error? What do I need to do to overcome this.
Try compile with this builder
replace in ./config.cong you are using 2.10
# PJSIP Version to download
PJSIP_VERSION=2.10
./prepare-build-system
and then
./build

"/system/bin/linker: No such file or directory" error trying to compile TensorFlow

I am trying to compile tensorflow-lite for Android running the building script, but the building process stops with this error:
/system/bin/linker: No such file or directory
I can understand how the building process works (compilation + linking) but I can not figure out why this '/system/bin/linker' is needed. This linker is not present in the SDK or NDK folder, and it is not present in the folder tree of the host computer (I am using Linux for the building process).
It looks like part of the Android file structure, but the building process should not depend on the final system structure.
The element I am trying to build is 'schema_fbs', which compiles part of the code using flatbuffers (a 3rd party dependency). The complete sentence I am using is:
bazel build \
--cxxopt='--std=c++11' \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=#bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a \
--verbose_failures \
--subcommands \
//tensorflow/contrib/lite/schema:schema_fbs
It could be caused by a testing case inside the Bazel building script (I have commented all the tests I found), but why is the linker needed? Is there something I have to do to define this 'system' folder in the compilation process?
Notes:
Target OS: Android
Host OS: Ubuntu 16.04
Used NDK: v16b (tested with v17 but it is not compatible)
Full error messages:
INFO: Analysed target //tensorflow/contrib/lite/schema:schema_fbs_srcs (0 packages loaded).
INFO: Found 1 target...
SUBCOMMAND: # //tensorflow/contrib/lite/schema:schema_fbs_srcs [action 'Generating flatbuffer files for schema_fbs_srcs: //tensorflow/contrib/lite/schema:schema_fbs_srcs']
(cd /home/user/.cache/bazel/_bazel_user/73606864f5ec4cce18dd83a6cbcd2bc2/execroot/org_tensorflow && \
exec env - \
LD_LIBRARY_PATH=/usr/local/lib:/home/user/Libraries/llvm-4.0.0.src/build/lib: \
PATH=/home/user/Software/git-sizer:/home/user/Android/Sdk/platform-tools:/home/user/anaconda3/bin:/home/user/Libraries/llvm-4.0.0.src/build/bin:/home/user/bin:/home/user/repo/caffe/build/install/lib:/home/user/Software/cmake-3.10.3-Linux-x86_64/bin:::::/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; for f in tensorflow/contrib/lite/schema/schema.fbs; do bazel-out/armeabi-v7a-opt/bin/external/flatbuffers/flatc --no-union-value-namespacing --gen-object-api -c -o bazel-out/armeabi-v7a-opt/genfiles/tensorflow/contrib/lite/schema $f; done')
ERROR: /home/user/Repositories/git/tensorflow/tensorflow/contrib/lite/schema/BUILD:57:1: Generating flatbuffer files for schema_fbs_srcs: //tensorflow/contrib/lite/schema:schema_fbs_srcs failed (Exit 255): bash failed: error executing command
(cd /home/user/.cache/bazel/_bazel_user/73606864f5ec4cce18dd83a6cbcd2bc2/execroot/org_tensorflow && \
exec env - \
LD_LIBRARY_PATH=/usr/local/lib:/home/user/Libraries/llvm-4.0.0.src/build/lib: \
PATH=/home/user/Software/git-sizer:/home/user/Android/Sdk/platform-tools:/home/user/anaconda3/bin:/home/user/Libraries/llvm-4.0.0.src/build/bin:/home/user/bin:/home/user/repo/caffe/build/install/lib:/home/user/Software/cmake-3.10.3-Linux-x86_64/bin:::::/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; for f in tensorflow/contrib/lite/schema/schema.fbs; do bazel-out/armeabi-v7a-opt/bin/external/flatbuffers/flatc --no-union-value-namespacing --gen-object-api -c -o bazel-out/armeabi-v7a-opt/genfiles/tensorflow/contrib/lite/schema $f; done')
/system/bin/linker: No such file or directory
Target //tensorflow/contrib/lite/schema:schema_fbs_srcs failed to build
INFO: Elapsed time: 0.572s, Critical Path: 0.02s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
The TensorFlow Lite AAR can also be built using:
bazel build --cxxopt='--std=c++11' -c opt --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a tensorflow/contrib/lite/java:tensorflow-lite
And you must make sure you ran ./configure and let it configure SDK and NDK for your.

Install valgrind for android, C compiler doesn't work

I'm trying to configure valgrind for android on Windows 7. I'm using guide from this site, but there is a problem with C compiler while configure. I'm using cygwin.
Error:
configure:3531: error: in /cygdrive/c/Tools/valgrind-3.9.0':
configure:3533: error: C compiler cannot create executables
Script:
#!/bin/bash
export NDKROOT=C:/Tools/AndroidNDK-r6
export HWKIND=generic # A generic Android device. eg, Pandaboard
export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ar.exe
export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ld.exe
export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
make
make install
and config.log file
Obviously, there's a kind of a problem executing the compiler from within the NDK folder. The log file states:
configure:3422: checking for C compiler version
configure:3431: C:/Tools/AndroidNDK-r6
/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
--version >&5
./configure: line 3433: C:/Tools/AndroidNDK-r6
/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
: No such file or directory
So next you want to make sure that the path actually exists and the compiler executable is executable indeed. You can try yourself to type directly in cygwin shell:
C:/Tools/AndroidNDK-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe -v
...and see what happens.

Cross-Compiling GCC for ARM Android. Build Fails At GMP

I'm at the end of my rope on this one.
I'm new to Android development. I've read the GCC install documentation and parts of Embedded Android. I'm trying to cross-compile gcc 4.7 using an Android NDK toolchain built with the make-standalone-toolchain.sh script. I'm using the gcc and binutils source files from the NDK toolchain sources.
I copied the gcc-4.7 and binutils-2.23 into a directory gcc-src and created a 'build' directory alongside both, as follows:
gcc-src/gcc-4.7
gcc-src/binutils-2.23
gcc-src/build
I've symlinked the sources for
bfd,
gas,
gprof,
ld,
gprof
opcodes
from binutils to the gcc-4.7 source directory. I also ran the script in contrib/ that downloads the relevant sources for
gmp,
mpfr
mpc
and creates the appropriate symlinks
I've run configure with the (latest) following options:
sh ../gcc-4.7/configure --prefix=/usr/arm --disable-option-checking --host=arm-linux-eabi
--target=arm-linux-eabi --with-sysroot=/usr/sysroot --with-build-sysroot=/usr/sysroot --with-build-time-tools=/usr/bin --program-prefix=arm-
--disable-multilib --with-cpu=arm7 --enable-languages=c,c++,lto --disable-werror --disable-nls CC=arm-linux-androideabi-gcc GCC=arm-linux-androideabi-gcc
CFLAGS='-Wall -g -mfloat-abi=softfp -mbionic -mandroid -Wl,-lsupc++ -Wl,-lgnustl_shared'
CPPFLAGS='-Wall -g -mbionic -mandroid' LDFLAGS='-Wl,-lsupc++ -Wl,-lgnustl_shared' CXX=arm-linux-androideabi-g++
LD=arm-linux-androideabi-ld STRIP=arm-linux-androideabi-strip OBJDUMP=arm-linux-androideabi-objdump READELF=arm-linux-androideabi-readelf
AS=arm-linux-androideabi-as NM=arm-linux-androideabi-nm
LIBS='-lc -ldl -lm' CC_FOR_TARGET=arm-linux-androideabi-gcc CPP_FOR_TARGET=arm-linux-androideabi-gcc CXX_FOR_TARGET=arm-linux-androideabi-g++
GCC_FOR_TARGET=arm-linux-androideabi-gcc RANLIB_FOR_TARGET=arm-linux-androideabi-gcc-ranlib LD_FOR_TARGET=arm-linux-androideabi-ld
AS_FOR_TARGET=arm-linux-androideabi-as NM_FOR_TARGET=arm-linux-androideabi-gcc-nm AR_FOR_TARGET=arm-linux-androideabi-gcc-ar
READELF_FOR_TARGET=arm-linux-androideabi-readelf
OBJDUMP_FOR_TARGET=arm-linux-androideabi-objdump STRIP_FOR_TARGET=arm-linux-androideabi-strip
host_configargs=--with-headers=/usr/sysroot/usr/include target_configargs=/usr/sysroot/usr/include
When I run make -d...or make -d all-host...it constantly fails when it tries to compile gen-fac_ui.c because it can't find the includes stdio.h, stdint.h or string.h.
I'll add the exact error tomorrow after I re-set my build directory and start again, but I wanted to post the details and problem tonight before I pass out.
Any help...is greatly appreciated. I'm at a loss on this one.
QUICK NOTE: I noticed that the binutils src directory contains an include/ folder...I'll try symlinking that into the gcc src directory and running 'make distclean' then '../gcc-4.7/configure && make again.'
UPDATE: symlinking include/ did not fix the problem. Here's the error I'm continuously getting
make[2]: Entering directory `/project/android/tc-src/gcc/gcc-src/build/gmp'
gcc `test -f 'gen-fac_ui.c' || echo '../../gcc-4.7/gmp/'`gen-fac_ui.c -o gen-fac_ui
Putting child 0x007ddd30 (gen-fac_ui) PID 25531 on the chain.
Live child 0x007ddd30 (gen-fac_ui) PID 25531
../../gcc-4.7/gmp/gen-fac_ui.c:20:19: error: stdio.h: No such file or directory
../../gcc-4.7/gmp/gen-fac_ui.c:21:20: error: stdlib.h: No such file or directory
In file included from ../../gcc-4.7/gmp/gen-fac_ui.c:23:
../../gcc-4.7/gmp/dumbmp.c:42:20: error: string.h: No such file or directory
In file included from ../../gcc-4.7/gmp/gen-fac_ui.c:23:
I successfully compiled gen-fac_ui by doing the following:
Uninstalling the build gcc which is not (I think) needed as I'm using the cross-compiler toolchain generated by the make-standalone-toolchain.sh script from the Android NDK
Configuring the appropriate variables to set up the cross-compiler tools as the BUILD tools.
I have a different problem now, which I'll post in a different question. Basically, while gen-fac_ui compiles, it (of course) won't run.

Build script for Android NDK in linux

How can I build my source for android with NDK.
Already I download ndk and I don't know how can I set arch compiler path.
This is my "build-for-android.sh" code:
#!/bin/sh
cairo=system
curl=system
pal=android
alsa=no
pulse=no
sles=yes
ffmpeg=yes
gallium=no
egl=yes
glx=no
PKG_CONFIG_PATH=$MOONLIGHT_PREFIX/lib/pkgconfig
if [ -d /usr/X11/share/aclocal ]; then
export ACLOCAL_FLAGS="-I /usr/X11/share/aclocal"
fi
./autogen.sh --host=arm-linux-androideabi --prefix=$MOONLIGHT_PREFIX --with-manual-mono=yes --with-testing=no --enable-browser-support --disable-desktop-support --with-unwind=no --with-ffmpeg=$ffmpeg --with-alsa=$alsa --with-pulseaudio=$pulse --with-opensles=$sles --with-pal=$pal --with-curl=$curl --with-cairo=$cairo --with-gallium-path=$gallium --enable-sdk=no --with-egl=$egl --with-glx=$glx CFLAGS="-DPLATFORM_ANDROID -I$MOONLIGHT_PREFIX/include $CFLAGS" LDFLAGS="-L$MOONLIGHT_PREFIX/lib $LDFLAGS" CXXFLAGS="-fno-rtti -DPLATFORM_ANDROID -I$MOONLIGHT_PREFIX/include $CFLAGS"
make $#
when I run it I get error below:
checking for arm-linu-androideabi-g++... no
checking for arm-linu-androideabi-c++... no
checking for arm-linu-androideabi-gpp... no
checking for arm-linu-androideabi-aCC... no
checking for arm-linu-androideabi-cc... no
.
.
.
.
I can see them in ~/Android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.4.3/prebuild/linux-x86/bin/* directory.
OK. I found it.:
First, a standalone toolchain is created to make the configure script easier to use
~$ android-ndk-r5b/build/tools/make-standalone-toolchain.sh --platform=android-8 --install-dir=android-8-toolchain
Next, the toolchain's bin directory is added to the PATH.
~$ export PATH=$PATH:~/android-8-toolchain/bin/

Categories

Resources