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
Related
I'm trying to cross compile (for armv7a and aarch64, android) the gettext library (dependency for glib). The configuration and compilation is successful, but during installation a relink error occurs:
libtool: relink: /home/user/dev/android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang -shared -fPIC -DPIC .libs/libgettextsrc_la-message.o .libs/libgettextsrc_la-po-error.o .libs/libgettextsrc_la-po-xerror.o .libs/libgettextsrc_la-read-catalog-abstract.o .libs/libgettextsrc_la-po-lex.o .libs/libgettextsrc_la-po-gram-gen.o .libs/libgettextsrc_la-po-charset.o .libs/libgettextsrc_la-read-po.o .libs/libgettextsrc_la-read-properties.o .libs/libgettextsrc_la-read-stringtable.o .libs/libgettextsrc_la-open-catalog.o .libs/libgettextsrc_la-dir-list.o .libs/libgettextsrc_la-str-list.o .libs/libgettextsrc_la-read-catalog.o .libs/libgettextsrc_la-write-catalog.o .libs/libgettextsrc_la-write-properties.o .libs/libgettextsrc_la-write-stringtable.o .libs/libgettextsrc_la-write-po.o .libs/libgettextsrc_la-msgl-ascii.o .libs/libgettextsrc_la-msgl-iconv.o .libs/libgettextsrc_la-msgl-equal.o .libs/libgettextsrc_la-msgl-cat.o .libs/libgettextsrc_la-msgl-header.o .libs/libgettextsrc_la-msgl-english.o .libs/libgettextsrc_la-msgl-check.o .libs/libgettextsrc_la-file-list.o .libs/libgettextsrc_la-msgl-charset.o .libs/libgettextsrc_la-po-time.o .libs/libgettextsrc_la-plural-exp.o .libs/libgettextsrc_la-plural-eval.o .libs/libgettextsrc_la-plural-table.o .libs/libgettextsrc_la-sentence.o .libs/libgettextsrc_la-format.o .libs/libgettextsrc_la-format-c.o .libs/libgettextsrc_la-format-python.o .libs/libgettextsrc_la-format-python-brace.o .libs/libgettextsrc_la-format-java.o .libs/libgettextsrc_la-format-java-printf.o .libs/libgettextsrc_la-format-csharp.o .libs/libgettextsrc_la-format-javascript.o .libs/libgettextsrc_la-format-scheme.o .libs/libgettextsrc_la-format-lisp.o .libs/libgettextsrc_la-format-elisp.o .libs/libgettextsrc_la-format-librep.o .libs/libgettextsrc_la-format-ruby.o .libs/libgettextsrc_la-format-sh.o .libs/libgettextsrc_la-format-awk.o .libs/libgettextsrc_la-format-lua.o .libs/libgettextsrc_la-format-pascal.o .libs/libgettextsrc_la-format-smalltalk.o .libs/libgettextsrc_la-format-qt.o .libs/libgettextsrc_la-format-qt-plural.o .libs/libgettextsrc_la-format-kde.o .libs/libgettextsrc_la-format-kde-kuit.o .libs/libgettextsrc_la-format-boost.o .libs/libgettextsrc_la-format-tcl.o .libs/libgettextsrc_la-format-perl.o .libs/libgettextsrc_la-format-perl-brace.o .libs/libgettextsrc_la-format-php.o .libs/libgettextsrc_la-format-gcc-internal.o .libs/libgettextsrc_la-format-gfc-internal.o .libs/libgettextsrc_la-read-desktop.o .libs/libgettextsrc_la-locating-rule.o .libs/libgettextsrc_la-its.o .libs/libgettextsrc_la-search-path.o -L/opt/android/armv7a-linux-androideabi26/lib -L/home/user/dev/sources/gettext-0.21/gettext-tools/intl/.libs -L/opt/android/armv7a-linux-androideabi26/lib -lgettextlib -ltextstyle -lm -lintl -liconv -lc -g -O2 -Wl,-soname -Wl,libgettextsrc-0.21.so -o .libs/libgettextsrc-0.21.so-ltextstyle -lm -lintl -liconv -lc -g -O2 -Wl,-soname -Wl,libgettextsrc-0.21.so -o .libs/libgettextsrc-0.21.so
ld: error: unable to find library -lgettextlib
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
libtool: error: error: relink 'libgettextsrc.la' with the above command before installing it
At the same time, other libraries (libffi and libiconv) compiled and installed normally.
gettext version: 0.20.2 and 0.21
Android NDK version: r23b and r24
OS version: Ubuntu 20.04.4 LTS
I configure, compile and install like this:
export DEV=${HOME}/dev
export NDK=$DEV/android-ndk-r23b
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
#export TARGET=aarch64-linux-android
export TARGET=armv7a-linux-androideabi
export API=26
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
./configure --host $TARGET --prefix=/opt/android/$TARGET$API --disable-rpath --disable-libasprintf --disable-java --disable-native-java --disable-openmp --disable-curses
make
make install
How can this be fixed?
Thank you!
I was able to compile this library using an old version of the Android NDK (r15c). Based on the compilation of Wireshark 3.4.0. Changed only the following environment variables:
export TARGET=aarch64-linux-android
export HOST=aarch64-eabi
export ARCH=arm64
export TOOLCHAIN=${TARGET}
export NDK_TOOLCHAIN=${DEV}/android-ndk-toolchain-${ARCH}-r15c
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
I am trying to build libgmp with NDK as static (shared also doesn't work), I need this to link with nettle and gnutls. The versions I am using below:
GMP: 6.1.2
NDK: r16b
Target: x86_64
API: android-27
Env: Ubuntu 16.04 (Windows shell)
So I download a tar of libgmp from their website and then the android standalong toolchain:
$NDK/build/tools/make_standalone_toolchain.py --arch "x86_64" --api 27 \
--stl=libc++ --install-dir /tmp/android-toolchain --force
Set the environment to link with NDK
# Prefix is out the output folder location
PREBUILT=/tmp/android-toolchain
CROSS_COMPILE=$PREBUILT/bin/x86_64-
CFLAGS="-isystem /tmp/android-toolchain/sysroot/usr/include/x86_64/ -D__ANDROID_API__=27-I$PREFIX/include"
export LDFLAGS="-Wl,-rpath-link=/tmp/android-toolchain/sysroot/usr/lib -L$/tmp/android-toolchain/sysroot/usr/lib -lc -lm -ldl -llog -nostdlib -lgcc -L$PREFIX/lib"
export CPPFLAGS="$CFLAGS"
export CFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export CXX="clang++"
export AS="clang"
export CC="clang"
export NM="${CROSS_COMPILE}nm"
export STRIP="${CROSS_COMPILE}strip"
export RANLIB="${CROSS_COMPILE}ranlib"
export AR="${CROSS_COMPILE}ar"
export LD="${CROSS_COMPILE}ld"
then ran configure
./configure
--prefix=$PREFIX \
--host="x86_64-linux" \
--build=x86_64-unknown-linux-gnu \
--disable-dependency-tracking \
--enable-static \
--disable-shared \
|| exit 1
make -j4 || exit 1
Prefix points to output directory, (also tried host x86_64-linux-android). It configures but then after that when running make, it will try to compile a bunch of binaries that auto create a bunch of files such as gen-fib.c -> gen-fib binary.
Makefile then runs that binary to create the header file (fib_table.h) and the source fib_table.c. When Makefile runs (I believe something like)
gen-fib header <number> <number> > fib_table.h
It outputs nothing, so fib_table.h is empty (0 bytes). I tried to run it from command line and nothing appears. Tried to create a file in gen-fib.c and have it compiled to create a dummy file and nothing happens. The binary executes nothing, does not run at all!
Now I have compiled this successfully with arm64 (aarch64 or arm64-v8a) and x86 (and of course ran make distclean between different hosts). I tried to compare the config.log with x86 and x86_64 which the only difference being the host argument in the configure and x86 android toolchain. For my x86_64 log file you can read that here:
https://pastebin.com/LLEbDz11
If anyone knows why the binaries (like gen-fibs) do not run after compiling them for x86_64 (but other abi like x86 and arm64) please let me know.
Thanks in advance!!
I figured out that the binaries were not building because it was using the toolchain's clang. Using
export CC_FOR_BUILD=/usr/bin/gcc
Uses the gcc from linux to compile it correctly.
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.
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.