Compiling source outside of the NDK directory structure

249 views
Skip to first unread message

paulbutcher

unread,
Feb 5, 2010, 6:17:18 AM2/5/10
to android-ndk
Apologies if this is a FAQ (I'm new to Android development and this
group).

Has anyone had any luck compiling source without copying it into the
NDK directory structure? We have an established body of source with
its own directory structure, and copying it into the Android setup is
going to be a real pain. I'd be very grateful for any pointers, or
warnings of pitfalls that are going to bite me.

Thanks!

paul.butcher->msgCount++

paulbutcher

unread,
Feb 5, 2010, 7:31:32 AM2/5/10
to android-ndk
On Feb 5, 11:17 am, paulbutcher <p...@paulbutcher.com> wrote:
> Apologies if this is a FAQ (I'm new to Android development and this
> Has anyone had any luck compiling source without copying it into the
> NDK directory structure?

Sorry - upon rereading this, I realise that I wasn't as clear as I
might be. I know that I can symlink instead of copy. What I'm
wondering is whether anyone has had any luck compiling something which
is outside of the NDK structure entirely?

Thanks!

paul.butcher->msgCount++

Chris

unread,
Feb 5, 2010, 7:46:36 AM2/5/10
to android-ndk
Paul,

I'm in the same situation as you. None of my source is in the NDK
structure because it exists already on my HD for other platforms and
would be a nightmare to move. I put their makefile into Verbose mode
and copied the flags that the NDK sets up and then I wrote my own
makefile. I did that because I wanted complete control over the
compiler/linker but if you just want to have your structure live
elsewhere, that's simple. Just put a file called Application.mk in the
NDK/Apps/YourApp folder and have it point to your source path by
adding these 2 lines:

APP_PROJECT_PATH := $(call my-dir)/Path/To/Your/Source
APP_MODULES := name_of_your_module

There's more information about how to do this in the NDK docs folder
on your hard drive.

Hope that helps,
Chris

Dmitry Moskalchuk

unread,
Feb 5, 2010, 8:10:59 AM2/5/10
to andro...@googlegroups.com
Well, I have it successfully compiled. What I did is just looking on
android makefiles and got all options from there required to be passed
to gcc. Finally, I'm compiling my applications with something like this:

$NDKROOT/build/prebuilt/darwin-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc \
--sysroot $NDKROOT/build/platforms/android-3/arch-arm -fPIC -mandroid
-g -O2 \
-DNDEBUG -Wall -c /path/to/my/source.c -o /path/to/my/obj.o

$NDKROOT/build/prebuilt/darwin-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc
-nostdlib \
-Wl,-shared,-Bsymbolic -Wl,--no-undefined -Wl,-z,defs \
$NDKROOT/build/platforms/android-3/arch-arm/usr/lib/libc.so \
$NDKROOT/build/platforms/android-3/arch-arm/usr/lib/libstdc++.so \
$NDKROOT/build/platforms/android-3/arch-arm/usr/lib/libm.so \
-L$NDKROOT/build/platforms/android-3/arch-arm/usr/lib \
-Wl,-rpath-link=$NDKROOT/build/platforms/android-3/arch-arm/usr/lib \

$NDKROOT/build/prebuilt/darwin-x86/arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a
\
-shared -fPIC -o /path/to/my/lib.so /path/to/my/obj.o

Note that's not supported by android team and therefore official
makefiles could be changed in the future (new options could be
added/removed) without notification so you'll need to monitor situation
on your own.

Dmitry Moskalchuk

paulbutcher

unread,
Feb 5, 2010, 12:25:07 PM2/5/10
to android-ndk
Chris, Dmitry,

Many thanks for your replies - that's exactly what I was looking for.
I'll have a play and see how I get on.

Thanks again,

paul.butcher->msgCount++

KKK

unread,
Feb 5, 2010, 9:43:46 PM2/5/10
to android-ndk

One thing to keep in mind when writing your own make files/ build
scripts is - NDK is bound to change. having said that, i believe they
also support backward compatibility.
Best thing i could think of for this is to link the sources in to NDK
subdirs and do the make
$(MAKE) -C $(NDK_ROOT)/ APP="$(DUMMY_APP)" V=1 -B
clean all the links and DUMMY_APP after generating targets.
Reply all
Reply to author
Forward
0 new messages