Using ndk-build for various targets

227 views
Skip to first unread message

JugglingAnt

unread,
Oct 6, 2010, 11:28:12 AM10/6/10
to android-ndk
I have a big C++ system with lots of makefiles that have been
converted to Android makefiles in order to use the Android build
system. Now my problem is that I want to be able to build my system
for the x86 platform using the same Android makefiles, just by
replacing the compiler toolchain... (basically I don't want to
maintain two build systems using a completely different set of
makefiles)

I was hoping that I would be able to override somewhere on my
Android.mk the default toolchain and let it point to my own native g++
compiler but that seems not to be the case. I tried with the following
line in the Android.mk file:

LOCAL_CXX = g++

It seems to be ignored!

Does anybody know if what I am trying to do is possible?

Doug Schaefer

unread,
Oct 6, 2010, 1:51:31 PM10/6/10
to andro...@googlegroups.com
Probably not. The Android build and host builds are pretty different,
especially at link time.

I've been using CMake for projects that are multi-platform by using an
Android toolchain definition file. For an example, take a look at my
attempt at an irrlicht port on github here:
http://github.com/dschaefer/irrlicht-android at the cmake directory
and CMakeLists.txt file. What I do then is link in the library in the
Android.mk in my Android projects (which are here:
http://github.com/dschaefer/irrlicht-examples). You'll also find where
I compile the irrlicht library using the Windows SDK using CMake as
well. You can do the same with MSYS/MinGW if you'd like.

Of course, the android.cmake toolchain file will need to be updated to
match the NDK makefiles as they change. It would be nice if we could
have such a file as part of the NDK and make it easier to keep them in
sync.

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

David Turner

unread,
Oct 6, 2010, 7:03:25 PM10/6/10
to andro...@googlegroups.com
The support for x86 is currently experimental on Android (i.e. not official).
However, I assume that what you really want is the ability to build your program for your host operating system (e.g. Linux) with the NDK build system.

Have a look at the content of build/toolchains/<name>. What you want is probably possible if you add a new <name> there,
and modify the config.mk and setup.mk to reflect your host toolchain. Your setup.mk will probably be tiny in comparison, and
you will need to set NDK_TOOLCHAIN=<myname> in your environment in order to select your own toolchain during the build.

As far as I know, it is the only thing that depends on the target CPU / ABI when building.

Let me know if this works.

JugglingAnt

unread,
Oct 7, 2010, 11:33:16 AM10/7/10
to android-ndk
Thanks for the help!
@David: I followed your hint, and I managed to compile it (I am using
android-ndk-r4-crystax by the way).

This is what I had to do:

1.- export NDK_TOOLCHAIN=x86-4.2.1

2.- edit /home/ikve/android-ndk-r4-crystax/build/core/default-
application.mk by adding
APP_ABI := x86

3.- edit android-ndk-r4-crystax/build/toolchains/x86-4.2.1/setup.mk:

TOOLCHAIN_PREFIX variable points to android-ndk-r4-crystax/build/
prebuilt/linux-x86/x86-4.2.1/bin/ which does not exist.

Therefore I just commented out TOOLCHAIN_PREFIX, to take the g++ from
the host machine (eg. /usr/bin/g++)

4.- Next problem I had to face were some errors when compiling with
standard headers (string, ...). My host compiler was taking the
includes from the ndk toolchain, that is from: android-ndk-r4-crystax/
build/platforms/android-8/arch-x86/usr/include. I renamed this
directory so that g++ falls back to the host's include path and then
it worked fine.



On Oct 7, 1:03 am, David Turner <di...@android.com> wrote:
> The support for x86 is currently experimental on Android (i.e. not
> official).
> However, I assume that what you really want is the ability to build your
> program for your host operating system (e.g. Linux) with the NDK build
> system.
>
> Have a look at the content of build/toolchains/<name>. What you want is
> probably possible if you add a new <name> there,
> and modify the config.mk and setup.mk to reflect your host toolchain. Your
> setup.mk will probably be tiny in comparison, and
> you will need to set NDK_TOOLCHAIN=<myname> in your environment in order to
> select your own toolchain during the build.
>
> As far as I know, it is the only thing that depends on the target CPU / ABI
> when building.
>
> Let me know if this works.
>
> On Wed, Oct 6, 2010 at 5:28 PM, JugglingAnt <thejugglingmon...@gmail.com>wrote:
>
>
>
> > I have a big C++ system with lots of makefiles that have been
> > converted to Android makefiles in order to use the Android build
> > system. Now my problem is that I want to be able to build my system
> > for the x86 platform using the same Android makefiles, just by
> > replacing the compiler toolchain... (basically I don't want to
> > maintain two build systems using a completely different set of
> > makefiles)
>
> > I was hoping that I would be able to override somewhere on my
> > Android.mk the default toolchain and let it point to my own native g++
> > compiler but that seems not to be the case. I tried with the following
> > line in the Android.mk file:
>
> > LOCAL_CXX = g++
>
> > It seems to be ignored!
>
> > Does anybody know if what I am trying to do is possible?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

Doug Schaefer

unread,
Oct 7, 2010, 12:16:52 PM10/7/10
to andro...@googlegroups.com
Yes, that's kinda what I meant by not using the NDK build system to
build for your host. It assumes you're building an Android library.

> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages