I am trying to compile the tools in dahdi-linux-complete-2.10.2+2.10.2 for android.
I have used the below android_configure.sh file to do the ./configure. which is based on https://gist.github.com/nddrylliog/4688209
#!/bin/sh
export ANDROID_SDK=/home/aks/android4.2
# I put all my dev stuff in herej
export DEV_PREFIX=${ANDROID_SDK}/development/
# Don't forget to adjust this to your NDK path
#export ANDROID_NDK=${DEV_PREFIX}/ndk/
export CROSS_COMPILE=arm-linux-androideabi
# I chose the gcc-4.7 toolchain - works fine for me##!
export ANDROID_PREFIX=${ANDROID_SDK}/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6
# Apparently android-8 works fine, there are other versions, look them up
export SYSROOT=${ANDROID_SDK}/prebuilts/ndk/8/platforms/android-9/arch-arm
#export CROSS_PATH=/home/androida20/a20_rbox/lichee/out/android/common/buildroot/external-toolchain/arm-linux-gnueabi/bin
# Non-exhaustive lists of compiler + binutils
# Depending on what you compile, you might need more binutils than that
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib
# This is just an empty directory where I want the built objects to be installed
export PREFIX=${HOME}/android-prefix
# Don't mix up .pc files from your host and build target
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
# You can clone the full Android sources to get bionic if you want.. I didn't
# want to so I just got linker.h from here: http://gitorious.org/0xdroid/bionic
# Note that this was only required to build boehm-gc with dynamic linking support.
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include -I${ANDROID_SDK}/bionic"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} --sysroot=${SYSROOT} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"
./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} --with-dahdi=../linux "$#"
To Compile I ran below commands
./android_configure.sh
make
The make is showing below error
error: cannot find -lpthread
Below is the last error message from make
/home/androida20/a20_rbox/android4.2/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc --sysroot=/home/androida20/a20_rbox/android4.2/prebuilts/ndk/8/platforms/android-9/arch-arm -L/home/androida20/a20_rbox/android4.2/prebuilts/ndk/8/platforms/android-9/arch-arm/usr/lib -L/home/androida20/a20_rbox/android4.2/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/lib dahdi_cfg.o version.o libtonezone.a -lm -lpthread -o dahdi_cfg
/home/androida20/a20_rbox/android4.2/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpthread
collect2: ld returned 1 exit status
make: *** [dahdi_cfg] Error 1
Any help in this regard is appreciated. Thanks in Advance
In android it uses bionic which has it's own implementation of pthread, so aftre removing the -lpthread from makefile, it was able to compile.
Related
I'm trying to cross compile grpc C++ (https://github.com/grpc/grpc) for Android from Ubuntu using Android NDK CLANG compiler (arm-linux-androideabi-clang++).
I've tried below way to compile it for Android.
export PATH=/root/Android/arm-26-toolchain-clang/bin:$PATH
export SYSROOT=/root/Android/arm-26-toolchain-clang/sysroot
export CC="arm-linux-androideabi-clang --sysroot $SYSROOT"
export CXX="arm-linux-androideabi-clang++ --sysroot $SYSROOT"
make CFLAGS='-std=c11 -march=armv7-a -D__ANDROID_API__=26' CXXFLAGS='- std=c++11 -frtti -fexceptions -march=armv7-a -D__ANDROID_API__=26' LIBS='-llog -lz -lc++_static' -j2
It is throwing error while compiling zlib.c - error: implicit declaration of function
'lseek' is invalid in C99
How to specify to build using C11 using the above CLANG compiler?
When I allowed it to move ahead ignoring this error, it stopped at below -
./src/core/lib/surface/completion_queue.h:92:5: error: unknown type name
'grpc_experimental_completion_queue_functor'
grpc_experimental_completion_queue_functor* shutdown_callback);
I tried to compile the example from https://github.com/grpc/grpc/tree/master/examples/android/helloworld but it throws error in compiling boringssl.
Could you please help cross compiling gRPC for android for toolchain arm-linux-androideabi?
Thanks
I could build it following the cross compile instructions in the Makefile in grpc github repository. Created a shell script like below and it worked -
export GRPC_CROSS_COMPILE=true
export PATH=/home/ubuntu/stand-alone-toolchain/arm-26-toolchain-clang/bin:$PATH
export SYSROOT=/home/ubuntu/stand-alone-toolchain/arm-26-toolchain-clang/sysroot
export HOST_CC="/usr/bin/gcc"
export HOST_CXX="/usr/bin/g++"
export HOST_LD="/usr/bin/ld"
export CC="arm-linux-androideabi-clang --sysroot $SYSROOT"
export CXX="arm-linux-androideabi-clang++ --sysroot $SYSROOT"
export LD="arm-linux-androideabi-clang++"
export LDXX="arm-linux-androideabi-clang++"
export AR="arm-linux-androideabi-ar"
export STRIP="arm-linux-androideabi-strip"
export PROTOBUF_CONFIG_OPTS="--host=arm-linux-androideabi --with-sysroot=${SYSROOT} --with-protoc=/usr/local/bin/protoc CFLAGS='-march=armv7-a -D__ANDROID_API__=26' CXXFLAGS='-frtti -fexceptions -march=armv7-a -D__ANDROID_API__=26' LIBS='-llog -lz -lc++_static'"
export HAS_PKG_CONFIG=false
export GRPC_CROSS_LDOPTS="-L$SYSROOT -L/home/ubuntu/cross-grpc/grpc"
export GRPC_CROSS_AROPTS="rc --target=elf32-little"
make
You may build grpc libraries using cmake toolchain:
cd <your build directory>
export ANDROID_NDK=<path to your NDK>
cmake <path to your grpc source directory>\
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake\
-DANDROID_ABI=armeabi-v7a\
-DANDROID_PLATFORM=android-26\
-DANDROID_STL=c++_static\
-DRUN_HAVE_STD_REGEX=0\
-DRUN_HAVE_POSIX_REGEX=0\
-DRUN_HAVE_STEADY_CLOCK=0\
-DCMAKE_BUILD_TYPE=Release
cmake --build . --target grpc++
When the build is finished, all required static libraries should be generated:
find . -type f -name "*.a"
./libgrpc.a
./third_party/zlib/libz.a
./third_party/cares/cares/lib/libcares.a
./third_party/boringssl/crypto/libcrypto.a
./third_party/boringssl/ssl/libssl.a
./third_party/protobuf/libprotobuf.a
./libgpr.a
./libaddress_sorting.a
./libgrpc++.a
In my CMake project I use the android.toolchain.cmake.
I pass the following environment variables as defines:
export ANDROID_ABI="armeabi-v7a" # x86
export ANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.9" # "x86-4.9"
export ANDROID_API_LEVEL="23"
export QT_DIR="$HOME/Qt/5.7/android_armv7"
export ANDROID_STANDALONE_TOOLCHAIN="$HOME/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/"
export ANDROID_PREFIX="sdk-android-armv7" # sdk-android-x86
export ANDROID_TARGET="armv7" # x86
export QTAV_LIB_DIR="lib_android_arm" # lib_android_x86
I pass the variables the following way:
cmake -DUSE_COMPRESSED_FILES=1 -DJAVA_HOME="/usr/java/default/" -DANDROID_SDK="$ANDROID_HOME" -DQT_ANDROID_SDK_ROOT="$ANDROID_HOME" -DQT_ANDROID_ANT="$ANT_PATH" -DCMAKE_MODULE_PATH="../cmake" -DCMAKE_PREFIX_PATH="$QT_DIR/lib/cmake" -DCMAKE_TOOLCHAIN_FILE=../cmake/android.toolchain.cmake -DANDROID_NDK="$HOME/android-ndk-r12b" -DCMAKE_BUILD_TYPE=Debug -DANDROID_ABI="$ANDROID_ABI" -DANDROID_TOOLCHAIN_NAME="$ANDROID_TOOLCHAIN_NAME" -DANDROID_STANDALONE_TOOLCHAIN="$ANDROID_STANDALONE_TOOLCHAIN" -DANDROID_NATIVE_API_LEVEL="$ANDROID_API_LEVEL" -DQT_DIR="$QT_DIR" -DANDROID_PREFIX="$ANDROID_PREFIX" -DANDROID_TARGET="$ANDROID_TARGET" -DQTAV_LIB_DIR="$QTAV_LIB_DIR" ../
cmake --build .
When "Stripping libraries to minimize size." it says:
Command does not exist: /home/peter/android-ndk-r12b/toolchains/armeabi-v7a-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip
The path should be "arm-linux-androideabi-4.9" and not "armeabi-v7a-4.9". Why is the ANDROID_ABI used instead of the ANDROID_TOOLCHAIN_NAME?
I do not have these problems for x86:
export ANDROID_ABI="x86"
export ANDROID_TOOLCHAIN_NAME="x86-4.9"
export ANDROID_API_LEVEL="23"
export QT_DIR="$HOME/Qt5.7.0/5.7/android_x86"
export ANDROID_STANDALONE_TOOLCHAIN="$HOME/android-ndk-r12b/toolchains/x86-4.9/"
export ANDROID_PREFIX="sdk-android-x86"
export ANDROID_TARGET="x86"
export QTAV_LIB_DIR="lib_android_x86"
edit:
The strip command is set by the android.toolchain.cmake file:
set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
ANDROID_TOOLCHAIN_ROOT is set this way since I specified a NDK path:
# setup paths and STL for NDK
if( BUILD_WITH_ANDROID_NDK )
set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
so I guess ANDROID_GCC_TOOLCHAIN_NAME must be wrong? ANDROID_NDK_TOOLCHAINS_SUBPATH starts with "prebuilt" so it is correct. ANDROID_NDK_TOOLCHAINS_PATH ends with "toolchains" so it is correct, too.
ANDROID_GCC_TOOLCHAIN_NAME is set if it is not Clang (which it is not):
set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
so everything should work fine since my ANDROID_TOOLCHAIN_NAME has been specified as "arm-linux-androideabi-4.9" above but it does not.
edit2:
ANDROID_ABI is the value which is used instead. It is never used in any strip path as far as I can see it in the file "android.toolchain.cmake" but its value is copied to ANDROID_NDK_ABI_NAME as well which is neither used for any strip path.
edit3:
It might be an error in AddQtAndroidApk.cmake rather than the toolchain since the output is actually:
Stripping libraries to minimize size.
Command does not exist: /home/peter/android-ndk-r12b/toolchains/armeabi-v7a-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip
CMakeFiles/my_app_apk.dir/build.make:60: recipe for target 'run_android_deploy_qt' failed
Somehow the file qtdeploy.json.in got the WRONG entry
"toolchain-prefix": "#ANDROID_ABI#",
which was no problem for x86. Of course it should be:
"toolchain-prefix": "#ANDROID_TOOLCHAIN_MACHINE_NAME#",
Besides I removed the statement setting "ANDROID_STANDALONE_TOOLCHAIN" which is not necessary. I got the necessary information using
cmake -DCMAKE_VERBOSE_MAKEFILE=on ...
make VERBOSE=1
and looking at the Qt CMake package.
I need to compile mpich for android , I used NDK arm-linux-andoirdeabi-4.8 toolchain to cross compile mpi , I did the following
export PATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/:$PATH"
export SYS_ROOT="$NDK_ROOT/platforms/android-8/arch-arm/"
export CC="arm-linux-androideabi-gcc --sysroot=$SYS_ROOT"
export LD="arm-linux-androideabi-ld"
export AR="arm-linux-androideabi-ar"
./configure --host=arm-linux-androideabi --prefix=/Crosscompile2/jni/mpich/ LIBS="-lc -lgcc " --disable-shared --disable-fortran --disable-cxx
but I got the following error:
checking for pthread_key_create in -lpthread... no
checking checkpointing library... configure: error: pthreads is required for checkpointing, but was not found
configure: error: src/pm/hydra configure failed
when I added -lpthread
LIBS="-lc -lgcc -lpthread"
it didn't compile
checking whether the C compiler works... no
configure: error: C compiler cannot create executables
Android is special in that it implements pthreads, but does not have a separate libpthread.a. The easy workaround is to add an empty library to your toolchain usr/lib
$AR q $SYS_ROOT/usr/lib/libpthread.a
before running ./configure
For the libpthread problems, you have 2 options.
sed out the requirement from the configure/makefiles since pthread is included in bionics libc
Or
Create a libpthead that's a symlink to libc
cd $SYSROOT/usr/lib
ln -s libc.a libpthread.a
I'm trying to cross port a big autotools project to Android, but I'm having some issues with the NDK configuration (I guess). When I run the configure script, everything goes well until I reach a point where the C++ Standard Template Library support is checked. Then configure: error: C++ Standard Template Libary unsupported shows up.
Taking a closer look into the config.log I found
/home/user/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c --sysroot=/home/user/android-ndk-r10e/platforms/android-21/arch-arm -Wall -O2 -DNDEBUG conftest.cpp >&5
conftest.cpp:30:16: fatal error: list: No such file or directory
#include <list>
These are the values for the environment variables
export ANDROID_NDK_ROOT=/home/user/android-ndk-r10e
export SYS_ROOT=/home/user/android-ndk-r10e/platforms/android-21/arch-arm
export ANDROID_EABI=arm-linux-androideabi-4.9
export ANDROID_TOOLCHAIN=${ANDROID_NDK_HOME}/toolchains/${ANDROID_EABI}/prebuilt/linux-x86_64
export CC="$ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-g++"
export CFLAGS="--sysroot=${SYS_ROOT}"
export LDFLAGS="--sysroot=${SYS_ROOT}"
export CXXFLAGS="--sysroot=${SYS_ROOT}"
I guess that I'm missing some includes or some libraries on the command (Although they should be in the sysroot folder).
Thanks for your help
According to http://developer.android.com/intl/es/ndk/guides/standalone_toolchain.html
The C++ Standard Template Library is not included in the pre-built toolchain. You need to install a standalone toolchain so a stl implementation is copied into the platform. See the Advanced Method section of the link above to solve it.
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.