I was surprised to see that gcc enforces code to be position independent, even if such flag wasn't provided explicitly in the command line.
I suspect it might have to do with certain expectations from Android's dynamic loader (e.g. expectations on relocation types and freedom to put code wherever it wants) but I am not certain.
Can anybody explain why that really is?
$ arm-linux-androideabi-gcc --version | grep GCC
arm-linux-androideabi-gcc (GCC) 4.4.3
$ arm-linux-androideabi-gcc -v -S main.c |& grep fpic
/home1/local64/android-toolchain/bin/../libexec/gcc/arm-linux-androideabi/4.4.3/cc1 -quiet -v -iprefix /home1/local64/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/ -isysroot /home1/local64/android-toolchain/bin/../sysroot main.c -mbionic -fpic -quiet -dumpbase main.c -march=armv5te -mfloat-abi=soft -mfpu=vfp -auxbase main -version -o main.s
Starting with Android 4.1, Google is forcing full ASLR to overcome common security exploits, see this article for more details.
Position Independent Code (PIC) is required for this to work but also PIE (Position Independent Executable) too.
Related
I'm trying to cross compile Python 3.7 for Android. I see in my output that bz2 if failing with the following error
building '_bz2' extension
/home/dematic/SPE/python3-android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include/openssl -no-integrated-as -I. -I./Include -target aarch64-none-linux-androideabi22 -target aarch64-none-linux-androideabi22 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include -I. -I/home/dematic/SPE/python3-android/src/Python-3.7.3/Include -I/home/dematic/SPE/python3-android/src/Python-3.7.3 -c /home/dematic/SPE/python3-android/src/Python-3.7.3/Modules/_bz2module.c -o build/temp.linux-aarch64-3.7/home/dematic/SPE/python3-android/src/Python-3.7.3/Modules/_bz2module.o
/home/dematic/SPE/python3-android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include/openssl -no-integrated-as -shared -target aarch64-none-linux-androideabi22 -fuse-ld=lld -L /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -target aarch64-none-linux-androideabi22 -fuse-ld=lld -L /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -target aarch64-none-linux-androideabi22 -fuse-ld=lld -L /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -fPIC -target aarch64-none-linux-androideabi22 build/temp.linux-aarch64-3.7/home/dematic/SPE/python3-android/src/Python-3.7.3/Modules/_bz2module.o -L. -L/home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -lbz2 -lpython3.7m -o build/lib.linux-aarch64-3.7/_bz2.cpython-37m.so
ld.lld: error: /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib/libbz2.a(bzlib.o) is incompatible with aarch64linux
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am building bzip2 1.0.6 without any issues, but I assume I'm not linking to it correctly or some other issue. Is there some sort of other architecture I'm supposed to be building?
This is the project I'm trying to build with
https://github.com/GRRedWings/python3-android
I'm trying to cross compile Python 3.7 for Android. I see in my output that bz2 if failing with the following error
The Bzip2 makefiles are not written for cross-compiles. They effectively ignore a user's flags like CFLAGS and LDFLAGS. The makefiles actually blows away a user's CFLAGS and sets it to CFLAGS=-Wall -Winline -O2 -g $(BIGFILES). Your flags like -target aarch64-none-linux-androideabi22 are not used.
There are two Makefiles in play. One is called Makefile and it builds the static library, if I recall correctly. The second is Makefile-libbz2_so, and it build the shared object. You need to fix the omissions and apply the fixes to both makefiles.
You should probably use a patched Bzip like bzip2-noloader. It honors a user's CFLAGS, CXXFLAGS, LDFLAGS, etc. The check-in of interest is Commit 34d170f31106.
The makefile recipes in bzip2-noloader look similar to the following. They preserve Seward's original settings in BZIP_CFLAGS. But they also utilize CPPFLAGS and allow a user override in CFLAGS. The override will pickup your flags like -target aarch64-none-linux-androideabi22.
blocksort.o: blocksort.c
$(CC) $(CPPFLAGS) $(BZIP_CFLAGS) $(CFLAGS) -c blocksort.c
Programs use LDFLAGS as expected:
bzip2: libbz2.a bzip2.o
$(CC) $(CPPFLAGS) $(BZIP_CFLAGS) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
Finally, the bzip2-noloader fork also honor's PREFIX, DESTDIR, etc. So you can perform staged installs, too.
I am building bzip2 1.0.6 without any issues ...
You are probably building for i686 or x86_64, and not Aarch64. The problem does not surface until link time. You can use objdump to inspect the object files, if interested.
Also note the makefile does this:
CC=gcc
AR=ar
RANLIB=ranlib
LDFLAGS=
You may need to tweak those variable assignments, too. Sometimes ar and ranlib use unusual names, like ranlib-5.0. And also be sure the tools are on-path.
The way to write makefiles to avoid these sorts of problems is detailed at 7.2.3 Variables for Specifying Commands in the GNU Coding Standards. The short of it is, (1) leave CFLAGS (and friends) for the user; and (2) if a flag is needed, then always supply it.
The GNU Coding Standards uses this as an example:
CFLAGS = -g
ALL_CFLAGS = -I. $(CFLAGS)
.c.o:
$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
Users can override the default CFLAGS of -g, and -I is always added because it is needed for the compile.
I'm using CMake (generator is ninja) to build a shared library using the NDK toolchain (g++ 4.9). Below is the verbose output for building a single CPP file in the library when I build with ninja:
[34/164] /usr/local/bin/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -DANDROID -DBOOST_ALL_NO_LIB -fexceptions -frtti -fpic -Wno-psabi --sysroot=/usr/local/bin/android-ndk/platforms/android-15/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -isystem /usr/local/bin/android-ndk/platforms/android-15/arch-arm/usr/include -isystem /usr/local/bin/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /usr/local/bin/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /usr/local/bin/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -I/usr/local/bin/android-ndk/sources/android/cpufeatures -I/usr/local/bin/android-ndk/sources/android/native_app_glue -ICore/Artifacts/Android -IApplications/Survey/Source -ICore/UI/. -ICore/UI/Source -ICore/ThirdParty/PowerVR/sdk/Include -ICore/ThirdParty/PowerVR/tools/include -ICore/ThirdParty/PowerVR/tools/include/OGLES2 -ICore/ThirdParty/boost/include -ICore/ThirdParty/openssl/include -ICore/ThirdParty/sqlite/include -ICore/WebServices/Source -std=gnu++14 -MMD -MT Applications/Survey/CMakeFiles/Survey.dir/Source/View/RadioGroup.cpp.o -MF Applications/Survey/CMakeFiles/Survey.dir/Source/View/RadioGroup.cpp.o.d -o Applications/Survey/CMakeFiles/Survey.dir/Source/View/RadioGroup.cpp.o -c Applications/Survey/Source/View/RadioGroup.cpp
Note that I specify -DCMAKE_BUILD_TYPE=Release when I generate.
The -g option is not present in the command line invocation, however the final binary is 19MB:
-rwxrwxr-x 1 bamboo bamboo 19173588 Jul 15 10:30 libzApp.so*
I ran size on it to determine what was making it so huge, but I got this:
$ size libzApp.so
text data bss dec hex filename
7097019 201268 53488 7351775 702ddf libzApp.so
That only accounts for 7mb of data. So I ran this:
$ objdump --debugging libzApp.so | head -25
libzApp.so: file format elf32-little
Contents of the .debug_abbrev section:
Number TAG (0x0)
1 DW_TAG_compile_unit [has children]
DW_AT_producer DW_FORM_strp
DW_AT_language DW_FORM_data1
DW_AT_name DW_FORM_strp
DW_AT_comp_dir DW_FORM_strp
DW_AT_low_pc DW_FORM_addr
DW_AT_entry_pc DW_FORM_addr
DW_AT_ranges DW_FORM_data4
DW_AT_stmt_list DW_FORM_data4
DW_AT value: 0 DW_FORM value: 0
2 DW_TAG_typedef [no children]
DW_AT_name DW_FORM_strp
DW_AT_decl_file DW_FORM_data1
DW_AT_decl_line DW_FORM_data1
DW_AT_type DW_FORM_ref4
DW_AT value: 0 DW_FORM value: 0
3 DW_TAG_base_type [no children]
DW_AT_byte_size DW_FORM_data1
DW_AT_encoding DW_FORM_data1
I think this pretty much confirms that it has debug symbols. Can anyone help me understand why the .so is so large? Assuming it's because of debug symbols, what about the command line invocation would cause this?
EDIT
As suggested in the comments section, running strip on the SO file definitely brings its size down to expected value (basically what we see from the result of the size command). However, why would debug symbols be built into the shared object when I specifically told GCC to not build debug symbols? Am I missing something here?
I can suggest you to use strip to remove the debugging information, eg:
strip libzApp.so
That is not so bad to do that because, for example, Qt's build system qmake always do that in it's install target of resulting Makefile.
By default, compiler always add a relocation information and symbol table into the binary. It also adds a lot of other information which may be stripped out (see link on answer below).
You may also use -s parameter to the compiler:
g++ -s ...
According to the docs:
-s:
Remove all symbol table and relocation information from the executable.
This flag should work exactly as strip. Here is also some similiar answer on stackoverflow.
I am trying to use the Android NDK on Mountain Lion to build a library for Android, following this guide
http://masl.cis.gvsu.edu/2012/01/25/android-echoprint/
When it comes time to compile the library, I run:
cd <path to jni>
<ndk>/ndk-build
I get the following error:
Compile++ thumb : echoprint-jni <= AndroidCodegen.cpp
arm-linux-androideabi-g++: error trying to exec 'cc1plus': execvp: No such file or directory
make: *** [/Users/wingdom/Desktop/obj/local/armeabi/objs/echoprint-jni/AndroidCodegen.o] Error 1
I believe I have added everything I need to to my path variable:
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Developer/android-sdk/tools:/Developer/android-sdk/platform-tools:/Developer/android-ndk:/Developer/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin
What else do I need to do in order to get this to compile? I am using the r8b NDK currently, but have tried it with versions all the way back to 6.
EDIT:
I tried this solution: Error while building android ndk sample project
adding
export PATH=$PATH:/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2
to my path gets me this error:
cc1plus: error: unrecognized command line option "-mbionic"
cc1plus: error: unrecognized command line option "-mthumb"
cc1plus: error: unrecognized command line option "-mfpu=vfp"
/Users/wingdom/Desktop/jni/AndroidCodegen.cpp:1: error: bad value (armv5te) for -march= switch
/Users/wingdom/Desktop/jni/AndroidCodegen.cpp:1: error: bad value (xscale) for -mtune= switch
make: *** [/Users/wingdom/Desktop/obj/local/armeabi/objs/echoprint-jni/AndroidCodegen.o] Error 1
but adding
export CROSS_COMPILER=$PATH:/Developer/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin
doesn't help, like it did in the link above.
I have experienced same error.
I was not able to execute even 'gcc, g++' command. So I have googled a lot to find solution, but nothing helped for me.
Then, I found that some filename in ndk is not correct, with tailing _ on some filename.. (In my case, in toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/arm-linux-androideabi/bin folder, there are gcc_, g++_, c++_ instead of gcc, g++, c++.)
I used The unarchiver to extract NDK archive, so I think there are something wrong with unarchiving procedure.
So I re-downloaded NDK and checked MD5 checksum, then extracted archive using Mac's default archive utility.
Now, the problem has solved.
Sounds like you have a bad download/unpack of the NDK. The cc1plus binary that it's looking for should be in $NDK_HOME/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/libexec/gcc/arm-linux-androideabi/4.4.3/. If it's not there, try re-downloading the SDK and/or unpacking it again.
If it is there, be sure to build passing V=1 to ndk-build, and see if there are any odd -B options passed to the compiler. The -B option tells gcc where to find its "sub-programs" (of which cc1plus is one). Pretty sure there shouldn't be any on the command lines for r8, so if there are, something somewhere is passing bad flags. For example, on my system, a C++ NDK command line ends up looking something like this:
/opt/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/sometarget/SomeCppFile.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I/opt/android-ndk/sources/cxx-stl/stlport/stlport -I/opt/android-ndk/sources/cxx-stl//gabi++/include -DANDROID -Wall -Wa,--noexecstack -frtti -O2 -DNDEBUG -g -I/opt/android-ndk/platforms/android-8/arch-arm/usr/include -c jni/SomeCppFile.cpp -o ./obj/local/armeabi-v7a/objs/sometarget/SomeCppFile.o
Maybe you need to install the g++:
$sudo apt-get install g++
I have spent about a day to find root cause of this
arm-linux-androideabi-gcc: error trying to exec 'cc1': execvp: No such file...
and others issues.
The issues were that I unpacked NDK and SDK with 7z which removed executable permission for all binaries and Eclipse was not able to start cc1.
Once I unpacked tar files of SDK and NDK using tar, everything started working well.
I am trying to cross-compile a very simple program for Android that worked with android-ndk-r6b and prior, but does not work on android-ndk-r7 and newer:
int main() {
;
return 0;
}
I was able to do so using an "agcc" script on an older version of Android that can be found here. I'm sincerely not trying to use an Android.mk file to build this. I know I can, but this is part of something much larger I'm working on. So take it for face-value that I am trying to cross-compile this in a different way.
Anyway, I try to build and get:
$ arm-eabi-gcc -o test test.c
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: warning: /tmp/cc00QD3x.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
/tmp/cc00QD3x.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
collect2: ld returned 1 exit status
So, the key error is the undefined reference to __aeabi_unwind_cpp_pr0.
After doing some digging, this symbol is in libgcc.a which I am linking to:
$ arm-eabi-nm /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a | grep __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
00000590 T __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
It has a 'T' which tells me that it is in the code somewhere, right?
Here is the verbose output of arm-eabi-gcc which shows I am in fact linking to this library:
Using built-in specs.
Target: arm-eabi
Configured with: /home/jingyu/projects/gcc/android-toolchainsrc/build/../gcc/gcc-4.4.3/configure --prefix=/usr/local --target=arm-eabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/home/jingyu/projects/gcc/toolchain_build/obj/temp-install --with-mpfr=/home/jingyu/projects/gcc/toolchain_build/obj/temp-install --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --with-abi=aapcs --with-gcc-version=4.4.3 --with-binutils-version=2.19 --with-gmp-version=4.2.4 --with-mpfr-version=2.4.1 --with-gdb-version=7.1.x --with-arch=armv5te --with-multilib-list=mandroid --with-sysroot=/usr/local/google/home/android/cupcake_rel_root --program-transform-name='s&^&arm-eabi-&'
Thread model: single
gcc version 4.4.3 (GCC)
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/cc1 -quiet -v -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -iprefix /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/ -D__USES_INITFINI__ -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -UDEBUG test.c -quiet -dumpbase test.c -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -mfpu=vfp -mabi=aapcs -auxbase test -version -fpic -fno-exceptions -ffunction-sections -funwind-tables -fstack-protector -fmessage-length=0 -o /tmp/ccIIp1N2.s
GNU C (GCC) version 4.4.3 (arm-eabi)
compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4), GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128206
ignoring nonexistent directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/include"
ignoring nonexistent directory "/usr/local/google/home/android/cupcake_rel_root/usr/local/include"
ignoring duplicate directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/include"
ignoring duplicate directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/include-fixed"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/include"
ignoring nonexistent directory "/usr/local/google/home/android/cupcake_rel_root/usr/include"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/out/target/product/generic/obj/include"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates"
#include "..." search starts here:
#include <...> search starts here:
/home/gnychis/Documents/android/os/system/core/include
/home/gnychis/Documents/android/os/hardware/libhardware/include
/home/gnychis/Documents/android/os/hardware/ril/include
/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include
/home/gnychis/Documents/android/os/dalvik/libnativehelper/include
/home/gnychis/Documents/android/os/frameworks/base/include
/home/gnychis/Documents/android/os/external/skia/include
/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include
/home/gnychis/Documents/android/os/bionic/libc/include
/home/gnychis/Documents/android/os/bionic/libstdc++/include
/home/gnychis/Documents/android/os/bionic/libc/kernel/common
/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm
/home/gnychis/Documents/android/os/bionic/libm/include
/home/gnychis/Documents/android/os/bionic/libthread_db/include
/home/gnychis/Documents/android/os/bionic/libm/arm
/home/gnychis/Documents/android/os/bionic/libm
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/include
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/include-fixed
End of search list.
GNU C (GCC) version 4.4.3 (arm-eabi)
compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4), GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128206
Compiler executable checksum: c575b4a30c8a516a84cf6e49f2cb23d1
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/as -v -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -march=armv5te -mthumb-interwork -mfloat-abi=soft -mfpu=vfp -meabi=5 -o /tmp/ccGAKjxX.o /tmp/ccIIp1N2.s
GNU assembler version 2.19 (arm-eabi) using BFD version (GNU Binutils) 2.19
COMPILER_PATH=/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/
LIBRARY_PATH=/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib/
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/collect2 --sysroot=/usr/local/google/home/android/cupcake_rel_root -X -o test -L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3 -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib -T /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/arm-eabi/lib/ldscripts/armelf.x -dynamic-linker /system/bin/linker --gc-sections -z nocopyreloc --no-undefined -rpath-link=/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib32/libiberty.a /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a -lc -lm /tmp/ccGAKjxX.o
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: warning: /tmp/ccGAKjxX.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
/tmp/ccGAKjxX.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
collect2: ld returned 1 exit status
So I'm just a bit unsure why I am getting this undefined reference. I have used this same method of cross-compiling with a slightly different version of Android and had no issue.
Does anything stand out to anyone?
EDIT: The actual command generated is the following:
arm-eabi-gcc -o test -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -include /home/gnychis/Documents/android/os/system/core/include/arch/linux-arm/AndroidConfig.h -UDEBUG -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fstack-protector -fmessage-length=0 -Bdynamic -Wl,-T,/home/gnychis/Documents/android/os/build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -Wl,--no-undefined -Wl,-rpath-link=/home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib -L/home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib -nostdlib /home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o /home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a -lc -lm test.c
Here's your link like, broken out into multiple lines for clarity:
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/collect2 \
--sysroot=/usr/local/google/home/android/cupcake_rel_root \
-X \
-o test \
-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib \
-L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3 \
-L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc
-L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib
-T /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/arm-eabi/lib/ldscripts/armelf.x \
-dynamic-linker /system/bin/linker \
--gc-sections \
-z nocopyreloc \
--no-undefined \
-rpath-link=/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib \
/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o \
/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o \
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib32/libiberty.a \
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a \
-lc \
-lm \
/tmp/ccGAKjxX.o
As you can see, your own object file (the temporary one) is the very last item on the command line. This is just wrong. It needs to be before the libraries, at least, if it is to link correctly.
Basically, your agcc script is passing -nostdlib (which says that you know better) and then passing the libraries manually, but doing it in completely the wrong order. If you fix this, all should be well.
Link order is very important. Objects and libraries that provide symbols must be linked after objects and libraries that require symbols.
There were certain versions of the tools that could tolerate bad ordering, but I think that was a bug, or mis-feature, because newer toolchains cannot, and should not. Presumably this script was written for one of those.
Where to find: __aeabi_unwind_cpp_pr0 and other mysterious, undefined functions
(I had a similar problem error to what you describe, but found a different solution, that may be helpful to you or others)
I found 'libgccunwind.a' library in the Google NDK package which defines a number of these mysterious functions (they are functions referenced by libc.a and other libraries in the NDK package, but not defined in a standard library) I found them defined in a libgccunwind.a library in:
\sources\android\gccunwind\libs\armeabi
NM shows that they are defined in that lib from an 'unwind-arm.o' file:
nm libgccunwind.a
unwind-arm.o:
U _GLOBAL_OFFSET_TABLE_
00000cf8 T _Unwind_Complete
00000cfc T _Unwind_DeleteException
00000ba4 T _Unwind_GetCFA
00000408 t _Unwind_GetGR
00000474 t _Unwind_SetGR
000003c4 T _Unwind_VRS_Get
0000084c T _Unwind_VRS_Pop
00000430 T _Unwind_VRS_Set
00000844 T __aeabi_unwind_cpp_pr0
0000083c W __aeabi_unwind_cpp_pr1
00000834 W __aeabi_unwind_cpp_pr2
w __cxa_begin_cleanup
w __cxa_call_unexpected
w __cxa_type_match
U __exidx_end
U __exidx_start
00000d1c T __gnu_Unwind_Backtrace
w __gnu_Unwind_Find_exidx
Independant of the libgccunwind.a above, I searched for __aeabi_unwind_cpp_pr0 and unwind-arm.c and unwind.c, and found various c source, for example:
http://lxr.free-electrons.com/source/arch/arm/kernel/unwind.c?a=arm
http://opensource.apple.com/source/gcc/gcc-5646/gcc/config/arm/unwind-arm.c
These programs seem to be derived from a similar source. My guess is that these 'unwind_cpp' (and related functions) are called by the functions in libc.a when a function returns or on certain events so that these functions can perform some debugging or tracing operation.
In any event, adding that directory in a -L linker option and -lgccunwind linker option (after the -lc linker option) allowed the linker to find those 'undefined' functions -- and let me get to the next problem I have in cross compiling to ARM systems.
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).