I wonder how to use arm-linux-androideabi compiler.
That compiler is on android-ndk tool.
There is ndk-build tool on android-ndk tool. To compile ethercat stack, I need only arm-linux-androideabi compiler.
But, I saw this message.
root#ubuntu:/opt/android/android-ndk-r9c/jni# arm-linux-androideabi-gcc -o test test.c
/opt/android/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/opt/android/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/opt/android/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/opt/android/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: ld returned 1 exit status
How am I supposed to do this?
You need to let the compiler know where to look for these files.
Try using:
arm-linux-androideabi-gcc --sysroot=/opt/android/android-ndk-r9c/platforms/android-19/arch-arm -o test test.c
where 19 is android API level you want to use. You can find more info on docs/STANDALONE-TOOLCHAIN.html in your ndk dir.
Related
I'm trying to build my CMake project to Android platform. I used CMake 3.12.3 and ninja 1.9.0, and belowing is the toolchain file I used:
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_ANDROID_NDK "C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570")
set(CMAKE_ANDROID_ARCH_ABI "arm64-v8a")
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang")
set(CMAKE_ANDROID_STL_TYPE "c++_static")
set(CMAKE_SYSROOT "${CMAKE_ANDROID_NDK}/platforms/android-24/arch-arm64")
set(CMAKE_C_ANDROID_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/aarch64-linux-android")
set(CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/aarch64-linux-android")
It fails at configuration stage:
Android: Targeting API '24' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
Android: Selected Clang toolchain 'aarch64-linux-android-clang' with GCC toolchain ''
The C compiler identification is Clang 8.0.7
The CXX compiler identification is Clang 8.0.7
Check for working C compiler: C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
Check for working C compiler: C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: D:/projects/MyProject-android-arm64-ninja/CMakeFiles/CMakeTmp
Run Build Command:"D:/development/ninja-1.9.0/ninja.exe" "cmTC_70fcb"
[1/2] Building C object CMakeFiles/cmTC_70fcb.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_70fcb
FAILED: cmTC_70fcb
cmd.exe /C "cd . && C:\Users\myname\AppData\Local\Android\Sdk\ndk\20.0.5594570\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=aarch64-none-linux-android --gcc-toolchain=C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains//prebuilt/windows-x86_64 --sysroot=C:/Users/myname/AppData/Local/Android/Sdk/ndk/20.0.5594570/platforms/android-24/arch-arm64 -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=24 -fexceptions -g -fPIE -pie -Wl,--gc-sections CMakeFiles/cmTC_70fcb.dir/testCCompiler.c.o -o cmTC_70fcb && cd ."
ld: error: unable to find library -lgcc
ld: error: unable to find library -lgcc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
I noticed two unexpected behavior:
Although I specified CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION to clang, it still wants to use GCC libraries.
Although I specified C and CXX toolchain prefix, It still failed to to find binutils such as CMAKE_OBJDUMP, CMAKE_STRIP, CMAKE_OBJCOPY, CMAKE_NM.
So how should I make everything work?
I am getting this error while run configure script with Android NDK-standalone toolchain for a 3rd part C library.
configure:3463: arm-linux-androideabi-gcc -E conftest.c
conftest.c:19:17: fatal error: png.h: No such file or directory
#include <png.h>
How do I include png.h to arm-linux-androideabi-gcc compiler toolchain?
I found this article helpful: http://blog.stuff-o-matic.com/post/2013/09/07/Porting-a-C-game-to-Android,-the-case-of-Andy-s-Super-Great-Park
I have a c program that uses -lpcap, -lm, and -lpthread. I see the libraries in /usr/arm-linuxgnueabi/lib/. However, if I compile using the command
arm-linux-gnueabi-gcc -static *.c -L/usr/arm-linux-gnueabi/lib/ -lpcap -lm -lpthread -o dumps/forandroid
It gives the following error:
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find crt1.o: No such file or directory<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lpcap<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lm<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lpthread
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lc<br>
collect2: error: ld returned 1 exit status
How can I give the library path properly? I am trying to compile the program for android emulator running android 5.1. I am using mint 17.2 64 bit amd machine.
I solved the problem using ndk toolchain. I compiled libpcap for arm-linux and used the library. The following command does the job:
arm-linux-androideabi-gcc --sysroot=/home/shahrear/Android/ndk/platforms/android-21/arch-arm -fpie -fpic -I./pcap -I. *.c -L./lib -pie -lm -lpcap -o dumps/forandroid
My goal is to run MPICH on Android phones. I'm using Debian Jessie. I thought that I'll achieve that following this tutorial:
http://hex.ro/wp/projects/personal-cloud-computing/compiling-mpich2-for-android-and-running-on-two-phones/
but instead of creating toolchain with Buildroot I decided to create it from Android NDK, as on this site:
http://www.threadstates.com/articles/2013/setting-up-an-android-cross-compiling-environment-with-the-ndk.html
I tried to use MPICH library versions 2.1.4, 2.1.5, 3.0.4 and configure it using command:
sudo CFLAGS=" -march=armv5 -mfpu=vfp -static "
CC=/home/cerbia/android/bin/arm-linux-androideabi-gcc ./configure
--prefix=/home/cerbia/old --host=arm-linux --with-pm=smpd --disable-f77 --disable-fc
but I still had this kind of error:
configure: error: SMPD requires MD5 support, and configure could not
find either md5_calc in md5.h or MD5 in openssl/md5.h
I found, that it is connected with openssl version and I tried to follow this instruction:
Download, compile, modify and install OpenSSL to the NDK directory. cd ~ wget www.openssl.org/source/openssl-1.0.0g.tar.gz tar xvzf
openssl-1.0.0g.tar.gz cd openssl-1.0.0g ./config no-asm shared --prefix=$ANDROID_ROOT/platforms/android-3/arch-arm/usr
edit Makefile:
CC= arm-linux-gnueabi-gcc-4.6
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_N -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall -fPIC
DEPFLAG= -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_R C5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_STORE
PEX_LIBS=
EX_LIBS= -ldl
EXE_EXT=
ARFLAGS=
AR= arm-linux-gnueabi-ar $(ARFLAGS) r
RANLIB= arm-linux-gnueabi-ranlib
NM= arm-linux-gnueabi-nm
PERL= /usr/bin/perl
TAR= tar
TARFLAGS= --no-recursion
MAKEDEPPROG= gcc
LIBDIR=lib
Than instead of HIPL I tried to cross-compile MPICH in the analogous way as below
Download and cross-compile HIPL. cd ~ bzr co lp:hipl trunk cd trunk edit configure.ac and comment out all AM_CFLAGS autoreconf --install
./configure --disable-gcc-warn --disable-firewall -host=arm-linux
CC=arm-linux-gnueabi-gcc-4.6
CPPFLAGS="-I$ANDROID_ROOT/platforms/android-3/arch-arm/usr/include"
CFLAGS="-nostdlib"
LDFLAGS="-Wl,-rpath-link=$ANDROID_ROOT/platforms/android-3/arch-arm/usr/lib,-L$ANDROID_ROOT/platforms/android-3/arch-arm/usr/lib"
LIBS="-lc" make make all-am make[1]: Entering directory `/home/mkomu/projects/hipl-bzr/arm' CC lib/core/builder.lo In file
included from lib/core/debug.h:34:0,
from lib/core/crypto.h:43,
from lib/core/builder.c:100: lib/core/protodefs.h:917:5: error: unknown type name 'in_port_t'
lib/core/protodefs.h:929:5: error: unknown type name 'in_port_t'
lib/core/protodefs.h:1027:5: error: unknown type name 'in_port_t'
lib/core/protodefs.h:1036:5: error: unknown type name 'in_port_t'
lib/core/protodefs.h:1043:5: error: unknown type name 'in_port_t'
lib/core/protodefs.h:1054:5: error: unknown type name 'in_port_t'
lib/core/protodefs.h:1055:5: error: unknown type name 'in_port_t' ...
it comes from site: bugs.launchpad.net/hipl/+bug/715126
but I got the same errors as person there..
make[8]: Wejście do katalogu
`/home/cerbia/old/mpich2-1.3.2/src/mpid/ch3/channels/nemesis/nemesis/netmod/tcp'
CC tcp_finalize.c In file included from
tcp_finalize.c:7:0: tcp_impl.h:108:89: error: unknown type name
'in_port_t' make[8]: * [tcp_finalize.o] Błąd 1
Do you have any advices what I should try to make it working?
In Linux, in_port_t is typedefed as uint16_t in netinet/in.h. The only place this typedef is used is in the definition of sockaddr_in.
The Android NDK does not define or use in_port_t, but instead uses unsigned short int. To compile code using the Android NDK, either typedef in_port_t or replace it with unsigned short int.
I am trying to build libraw as a Android shared library. It looks the lib is too complex to use with Android.mk etc, or better: I am not capable yet of doing that.
I tried the route of using a standalone toolchain from the NDK, but I am getting stuck when compiling this lib.
This is the path I take to compile the lib. Please point out if I am making obvious errors:
I downloaded the ndk.
ran: make-standalone-toolchain.sh
Added the bin folder of that standalone toolchain as first item in my PATH.
Ran ./configure with --host=arm-linux-androideabi. This succeeded
Ran make, here it crashed very fast.
LibRaw-0.14.4$ make
depbase=`echo internal/dcraw_common.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/bash ./libtool --tag=CXX --mode=compile arm-linux-androideabi-g++ -DPACKAGE_NAME=\"LibRaw\" -DPACKAGE_TARNAME=\"libraw\" -DPACKAGE_VERSION=\"0.14.4\" -DPACKAGE_STRING=\"LibRaw\ 0.14.4\" -DPACKAGE_BUGREPORT=\"info#libraw.org\" -DPACKAGE_URL=\"http://www.libraw.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I/usr/local/include -g -O2 -MT internal/dcraw_common.lo -MD -MP -MF $depbase.Tpo -c -o internal/dcraw_common.lo internal/dcraw_common.cpp &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile: arm-linux-androideabi-g++ -DPACKAGE_NAME=\"LibRaw\" -DPACKAGE_TARNAME=\"libraw\" -DPACKAGE_VERSION=\"0.14.4\" "-DPACKAGE_STRING=\"LibRaw 0.14.4\"" -DPACKAGE_BUGREPORT=\"info#libraw.org\" -DPACKAGE_URL=\"http://www.libraw.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I/usr/local/include -g -O2 -MT internal/dcraw_common.lo -MD -MP -MF internal/.deps/dcraw_common.Tpo -c internal/dcraw_common.cpp -fPIC -DPIC -o internal/.libs/dcraw_common.o
internal/dcraw_common.cpp: In member function 'void LibRaw::read_shorts(ushort*, int)':
internal/dcraw_common.cpp:119: error: 'swab' was not declared in this scope
internal/dcraw_common.cpp: In member function 'void LibRaw::write_ppm_tiff()':
internal/dcraw_common.cpp:9235: error: 'swab' was not declared in this scope
make: *** [internal/dcraw_common.lo] Error 1
I doubt this error message is helpfull here at stackoverflow, but I am left wondering if I should have applied some additional flags or configuration to get this to work?
Note that I am able to compile this lib succesfully if just compiling for my system without crosscompiling. (linux 32bit).
When I am looking to a instruction for building GDAL for Android (here), it uses a additional setting of LIBS="-lsupc++ -lstdc++". This links the STL and C++ exceptions?
However, when I set those before running my configure I get immediately errors like:
configure:3018: checking whether the C++ compiler works
configure:3040: arm-linux-androideabi-g++ conftest.cpp -lsupc++ -lstdc++ >&5
/tmp/android-chain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lsupc++
collect2: ld returned 1 exit status
So, I am a bit stuck. Someone an idea?
I had to add an implementation of the swab function, since the NDK does not have that one.
Afterwards this compiled fine (but I used the crystax ndk).
A better way toolwise was to just use a Android.mk file and use ndk-build to compile it.
Linker error from the bottom of your question occurs because make-standalone-toolchain.sh from NDK r7 creates incomplete toolchain (it misses some libraries including libsupc++.a). I recommend you try making a toolchain from one of previous NDK releases (r6b should be fine).