Compile with Android NDK

889 views
Skip to first unread message

esio

unread,
Jul 27, 2011, 7:00:28 AM7/27/11
to android-ndk, zade...@gmail.com
Hi!
I am trying compile code with the x86 Android NDK. Unfortunely, this
is a multiplatform application.
On Linux, I compile using CMake scripts and the android and I want to
use them. I can compile my application if I have access to sources of
android and I use Android.mk but this solution does not satisfy me. I
would like to compile using only NDK, without Android sources.

I have:
1. standalone toolchain, created by $NDK/build/tools/make-standalone-
toolchain.sh --platform=android-9 --install-dir=/tmp/my-android-
toolchain --arch=x86
2. Toolchain.cmake file:


set(toolchain_path /opt/android-toolchain)
include(CMakeForceCompiler)

set(CMAKE_C_COMPILER ${toolchain_path}/bin/i686-android-linux-gcc -
nostdlib)
set(CMAKE_CXX_COMPILER ${toolchain_path}/bin/i686-android-linux-g++ -
nostdlib)

set(CMAKE_FIND_ROOT_PATH ${toolchain_path})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)


When compiling I've got the following error:
-- Check for working CXX compiler: /opt/android-toolchain/bin/i686-
android-linux-g++
-- Check for working CXX compiler: /opt/android-toolchain/bin/i686-
android-linux-g++ -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:
45 (MESSAGE):
The C++ compiler "/opt/android-toolchain/bin/i686-android-linux-g++"
is not
able to compile a simple test program.

I can compile a simple program using the NDK, but I have a problem
when compiling larger programs. I compile simple "Hello World" code
using this way:

/opt/android-toolchain/bin/i686-android-linux-gcc --sysroot=~/
Downloads/android-ndk-r6/platforms/android-9/arch-x86/ hw.c -nostdlib
and I recives warining:
/user/geliszew/Downloads/android-ndk-r6/toolchains/x86-4.4.3/prebuilt/
linux-x86/bin/../lib/gcc/i686-android-linux/4.4.3/../../../../i686-
android-linux/bin/ld: warning: cannot find entry symbol _start;
defaulting to 08048074

cat hw.c:
main() { return 0; }

System: Ubuntu 10.10 x64, kernel 2.6.35-22-generic
NDK-r6

Is anyone help me?

Marco Bernasocchi

unread,
Jul 27, 2011, 11:11:57 AM7/27/11
to andro...@googlegroups.com
I'm dealing with a large cmake based codebase (qgis.org) and i managed to cross compile using a standalone toolchain, thave a look at [0] to see if it can help you foremost my toolchain.cmake is a bit more complex, I toke it from android-cmake project [1]
ciao Marco

[0] https://github.com/mbernasocchi/qgis-android/
[1] http://code.google.com/p/android-cmake/
Reply all
Reply to author
Forward
0 new messages