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
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
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 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 currently trying to compile the libtorrent source files with Python bindings for Android. To do this, I have my custom toolchain with a compiled Boost library.
I use the following command to configure the libtorrent installation:
./configure --host=$CROSSHOST --prefix=$CROSSHOME --with-boost=$CROSSHOME --with-boost-libdir=$CROSSHOME/lib --enable-static --disable-shared --enable-debug --enable-logging --enable-python-binding
The variables are setup as follow:
export ANDROIDNDK='/home/martijn/Documenten/android-ndk-r9d'
export SYSROOT=$ANDROIDNDK/platforms/android-14/arch-arm
export PYTHON=/home/martijn/Documenten/python-for-android/build/python/Python-2.7.2/hostpython
export PYTHON_CPP_FLAGS="-I/home/martijn/Documenten/python-for-android/build/python/Python-2.7.2 -I/home/martijn/Documenten/python-for-android/build/python/Python-2.7.2/Include"
# Custom ARM toolchain
export SYSROOT=$ANDROIDNDK/platforms/android-14/arch-arm
export PATH=/usr/local/gcc-4.8.0-arm-linux-androideabi/bin:$PATH
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export CROSSHOST=arm-linux-androideabi
export CROSSHOME=/usr/local/gcc-4.8.0-arm-linux-androideabi
# Set ARM v5 architecture with debug flag!
export CFLAGS="-g"
export CXXFLAGS=$CLFAGS
Compiling without the --enable-python-binding flag gives no problem and I correctly get a libtorrent.so file. At the end of the compilation, I get the following error:
creating build/lib.linux-x86_64-2.7
arm-linux-androideabi-g++ arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/martijn/Documenten/android-ndk-r9d/platforms/android-14/arch-arm -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -shared -lm -L/home/martijn/Documenten/python-for-android/build/openssl/openssl-1.0.1g/ -g -fvisibility=hidden build/temp.linux-x86_64-2.7/src/alert.o build/temp.linux-x86_64-2.7/src/error_code.o build/temp.linux-x86_64-2.7/src/module.o build/temp.linux-x86_64-2.7/src/datetime.o build/temp.linux-x86_64-2.7/src/fingerprint.o build/temp.linux-x86_64-2.7/src/entry.o build/temp.linux-x86_64-2.7/src/session.o build/temp.linux-x86_64-2.7/src/torrent_info.o build/temp.linux-x86_64-2.7/src/magnet_uri.o build/temp.linux-x86_64-2.7/src/converters.o build/temp.linux-x86_64-2.7/src/string.o build/temp.linux-x86_64-2.7/src/utility.o build/temp.linux-x86_64-2.7/src/session_settings.o build/temp.linux-x86_64-2.7/src/create_torrent.o build/temp.linux-x86_64-2.7/src/big_number.o build/temp.linux-x86_64-2.7/src/torrent_handle.o build/temp.linux-x86_64-2.7/src/torrent_status.o build/temp.linux-x86_64-2.7/src/version.o build/temp.linux-x86_64-2.7/src/ip_filter.o build/temp.linux-x86_64-2.7/src/peer_info.o -L../../src/.libs -L/usr/local/ssl/lib -L. -ltorrent-rasterbar -lboost_system -lboost_python -lssl -lcrypto -lpython2.7 -o build/lib.linux-x86_64-2.7/libtorrent.so -L/usr/local/gcc-4.8.0-arm-linux-androideabi/lib
arm-linux-androideabi-g++: error: arm-linux-androideabi-gcc: No such file or directory
error: command 'arm-linux-androideabi-g++' failed with exit status 1
I'm not sure what's causing this error. I think have I my arm-linux-androieabi-g++ command setup correctly but maybe there's a setting that I oversee. Anyone here who can help me?