Build Android NDK with GNU Makefile

3,510 views
Skip to first unread message

gacon

unread,
Jul 12, 2010, 5:15:58 AM7/12/10
to android-ndk
Hi all,

Because I have so many c/c++ files, and sub-projects, so I don't want
to convert all Makefile to Android NDK Makefile, It will take a long
time to complete. So I tried to build NDK with GNU Makefile by using
this command: ndk-build -B --makefile=/path_to_makefile/Makefile

Everything is ok, but I don't have the lib file, because I got this
message:


[CODE]
gacon@gacon-laptop:~/workspace/faad2/jni$ ndk-build
Executable : faad2
/home/gacon/android/android-ndk-r4-crystax/build/platforms/android-8/
arch-arm/usr/lib/crtbegin_dynamic.o: In function `_start':
bionic/libc/arch-arm/bionic/crtbegin_dynamic.S:(.text+0x14): undefined
reference to `main'
collect2: ld returned 1 exit status
make: *** [/home/gacon/workspace/faad2/bin/ndk/local/armeabi/faad2]
Error 1
[/CODE]


Does anyone know where to change in GNU Makefile to force compiler to
build to lib instead of an executable?

Thanks,

Olivier Guilyardi

unread,
Jul 12, 2010, 8:37:52 AM7/12/10
to andro...@googlegroups.com
I believe that using the --makefile option is really non NDK compliant. You
shouldn't be doing that. And it that ever works, please consider that getting
something to build is one thing, but making it work on all the devices out there
is something else.

AFAIK writing Android.mk makefiles is the only option currently. And it doesn't
take so much time in my experience, especially if you use ./configure as I
mentioned recently, and then write Android.mk by reading Makefile.am which is
usually very readable.

Olivier

Ngo Van Luyen

unread,
Jul 12, 2010, 8:59:17 AM7/12/10
to andro...@googlegroups.com
Thank for your useful reply.

I tried to look at Makefile but there are so many thing there. I don't know which one I should copy to Android.mk. I tried to copy (with some modifications in path to source) the c/c++ source part (source:= ...). But when I type ndk-build, I got a blank screen, ndk-build shows me nothing.

Thanks,


2010/7/12 Olivier Guilyardi <li...@samalyse.com>
--
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.




--
Hello Android!
http://androidcore.com/

Olivier Guilyardi

unread,
Jul 12, 2010, 9:15:01 AM7/12/10
to andro...@googlegroups.com
You can't just copy stuff from Makefile to Android.mk. You need to understand
what happens and convert.

Do you have an (automake) Makefile.am or just a plain Makefile?

Olivier

On 07/12/2010 02:59 PM, Ngo Van Luyen wrote:
> Thank for your useful reply.
>
> I tried to look at Makefile but there are so many thing there. I don't
> know which one I should copy to Android.mk. I tried to copy (with some
> modifications in path to source) the c/c++ source part (source:= ...).
> But when I type ndk-build, I got a blank screen, ndk-build shows me nothing.
>
> Thanks,
>
>

> 2010/7/12 Olivier Guilyardi <li...@samalyse.com <mailto:li...@samalyse.com>>

> <mailto:andro...@googlegroups.com>.


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

> <mailto:android-ndk%2Bunsu...@googlegroups.com>.

Ngo Van Luyen

unread,
Jul 12, 2010, 10:25:29 AM7/12/10
to andro...@googlegroups.com
yes, I have Makefile.am file



2010/7/12 Olivier Guilyardi <li...@samalyse.com>

Olivier Guilyardi

unread,
Jul 12, 2010, 11:28:38 AM7/12/10
to andro...@googlegroups.com
Then, it should be simpler than a handwritten Makefile. Makefile.am is usually
quite readable.

Here's an autotools tutorial:
http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/

You need to understand the basics of autoconf, automake, etc.. to port your libs.

Also, the blank screen symptom that you mentioned before could be caused by an
incomplete Application.mk. Double check $NDK/docs.

Olivier

On 07/12/2010 04:25 PM, Ngo Van Luyen wrote:
> yes, I have Makefile.am file
>
>
>

> 2010/7/12 Olivier Guilyardi <li...@samalyse.com <mailto:li...@samalyse.com>>


>
> You can't just copy stuff from Makefile to Android.mk. You need to
> understand
> what happens and convert.
>
> Do you have an (automake) Makefile.am or just a plain Makefile?
>
> Olivier
>
> On 07/12/2010 02:59 PM, Ngo Van Luyen wrote:
> > Thank for your useful reply.
> >
> > I tried to look at Makefile but there are so many thing there. I don't
> > know which one I should copy to Android.mk. I tried to copy (with some
> > modifications in path to source) the c/c++ source part (source:= ...).
> > But when I type ndk-build, I got a blank screen, ndk-build shows
> me nothing.
> >
> > Thanks,
> >
> >
> > 2010/7/12 Olivier Guilyardi <li...@samalyse.com

> <mailto:li...@samalyse.com> <mailto:li...@samalyse.com

> > <mailto:andro...@googlegroups.com


> <mailto:andro...@googlegroups.com>>.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com
> <mailto:android-ndk%2Bunsu...@googlegroups.com>

> > <mailto:android-ndk%2Bunsu...@googlegroups.com
> <mailto:android-ndk%252Buns...@googlegroups.com>>.

Ngo Van Luyen

unread,
Jul 12, 2010, 3:47:55 PM7/12/10
to andro...@googlegroups.com
Thank you Olivier.


and playing with android makefile :)




2010/7/12 Olivier Guilyardi <li...@samalyse.com>

Olivier Guilyardi

unread,
Jul 12, 2010, 4:16:15 PM7/12/10
to andro...@googlegroups.com
Yep, this tutorial is the sort of thing that I meant.

I think you're on the right way :)

Olivier

On 07/12/2010 09:47 PM, Ngo Van Luyen wrote:
> Thank you Olivier.
>
> I have just found a nice presentation for beginner like
> me: http://androidcore.com/android-programming-tutorials/553-happy-how-to-porting-x86-application-to-android.html
>
> and playing with android makefile :)
>
>
>
>

> 2010/7/12 Olivier Guilyardi <li...@samalyse.com <mailto:li...@samalyse.com>>


>
> Then, it should be simpler than a handwritten Makefile. Makefile.am
> is usually
> quite readable.
>
> Here's an autotools tutorial:
> http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/
>
> You need to understand the basics of autoconf, automake, etc.. to
> port your libs.
>
> Also, the blank screen symptom that you mentioned before could be
> caused by an
> incomplete Application.mk. Double check $NDK/docs.
>
> Olivier
>
> On 07/12/2010 04:25 PM, Ngo Van Luyen wrote:
> > yes, I have Makefile.am file
> >
> >
> >
> > 2010/7/12 Olivier Guilyardi <li...@samalyse.com

> <mailto:li...@samalyse.com> <mailto:li...@samalyse.com


> <mailto:li...@samalyse.com>>>
> >
> > You can't just copy stuff from Makefile to Android.mk. You need to
> > understand
> > what happens and convert.
> >
> > Do you have an (automake) Makefile.am or just a plain Makefile?
> >
> > Olivier
> >
> > On 07/12/2010 02:59 PM, Ngo Van Luyen wrote:
> > > Thank for your useful reply.
> > >
> > > I tried to look at Makefile but there are so many thing
> there. I don't
> > > know which one I should copy to Android.mk. I tried to copy
> (with some
> > > modifications in path to source) the c/c++ source part
> (source:= ...).
> > > But when I type ndk-build, I got a blank screen, ndk-build shows
> > me nothing.
> > >
> > > Thanks,
> > >
> > >
> > > 2010/7/12 Olivier Guilyardi <li...@samalyse.com
> <mailto:li...@samalyse.com>
> > <mailto:li...@samalyse.com <mailto:li...@samalyse.com>>
> <mailto:li...@samalyse.com <mailto:li...@samalyse.com>

> > <mailto:li...@samalyse.com <mailto:li...@samalyse.com>>>>

> > > <mailto:android-ndk%2Bunsu...@googlegroups.com
> <mailto:android-ndk%252Buns...@googlegroups.com>
> > <mailto:android-ndk%252Buns...@googlegroups.com
> <mailto:android-ndk%25252Bun...@googlegroups.com>>>.

Ngo Van Luyen

unread,
Jul 13, 2010, 6:59:42 AM7/13/10
to andro...@googlegroups.com
I did it, thank you so much Olivier. I'm going to port my others libs :)

Olivier Guilyardi

unread,
Jul 13, 2010, 7:31:15 AM7/13/10
to andro...@googlegroups.com
You're welcome.

There's something wrong IMO with the tutorial you mention though. The way
./configure is called might lead to subtle problems in the generated config.h.

For example, with libsndfile, if you just run ./configure you get this in config.h:
#define SIZEOF_OFF_T 8

But if you properly configure it for ARM/NDK, config.h contains:
#define SIZEOF_OFF_T 4

Here's what I mean by properly configuring:

export NDK=/path/to/ndk
export PATH=$PATH:$NDK/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin

./configure \
--host=arm-eabi \
CC=arm-eabi-gcc \
CPPFLAGS="-I$NDK/build/platforms/android-3/arch-arm/usr/include/" \
CFLAGS="-nostdlib" \
LDFLAGS="-Wl,-rpath-link=$NDK/build/platforms/android-3/arch-arm/usr/lib/ \
-L$NDK/build/platforms/android-3/arch-arm/usr/lib/" \
LIBS="-lc "

Of course you can add other configure options, such as --disable-foobar, etc..

Olivier

On 07/13/2010 12:59 PM, Ngo Van Luyen wrote:
> I did it, thank you so much Olivier. I'm going to port my others libs :)
>
>
>

> 2010/7/12 Olivier Guilyardi <li...@samalyse.com <mailto:li...@samalyse.com>>


>
> Yep, this tutorial is the sort of thing that I meant.
>
> I think you're on the right way :)
>
> Olivier
>
> On 07/12/2010 09:47 PM, Ngo Van Luyen wrote:
> > Thank you Olivier.
> >
> > I have just found a nice presentation for beginner like
> > me:
> http://androidcore.com/android-programming-tutorials/553-happy-how-to-porting-x86-application-to-android.html
> >
> > and playing with android makefile :)
> >
> >
> >
> >
> > 2010/7/12 Olivier Guilyardi <li...@samalyse.com

> <mailto:li...@samalyse.com> <mailto:li...@samalyse.com


> <mailto:li...@samalyse.com>>>
> >
> > Then, it should be simpler than a handwritten Makefile.
> Makefile.am
> > is usually
> > quite readable.
> >
> > Here's an autotools tutorial:
> >
> http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/
> >
> > You need to understand the basics of autoconf, automake, etc.. to
> > port your libs.
> >
> > Also, the blank screen symptom that you mentioned before could be
> > caused by an
> > incomplete Application.mk. Double check $NDK/docs.
> >
> > Olivier
> >
> > On 07/12/2010 04:25 PM, Ngo Van Luyen wrote:
> > > yes, I have Makefile.am file
> > >
> > >
> > >
> > > 2010/7/12 Olivier Guilyardi <li...@samalyse.com
> <mailto:li...@samalyse.com>
> > <mailto:li...@samalyse.com <mailto:li...@samalyse.com>>

> > > <mailto:android-ndk%252Buns...@googlegroups.com
> <mailto:android-ndk%25252Bun...@googlegroups.com>
> > <mailto:android-ndk%25252Bun...@googlegroups.com
> <mailto:android-ndk%2525252Bu...@googlegroups.com>>>>.

charles

unread,
Jul 14, 2010, 5:29:03 AM7/14/10
to android-ndk
Here is how I do it.

http://wlan-lj.net/browser/trunk/meshapp/Makefile [Top level makefile]
http://wlan-lj.net/browser/trunk/meshapp/guilib/Makefile [Makes a
small static library libguilib.a]
http://wlan-lj.net/browser/trunk/meshapp/guilib/make/Makefile.android
[Compiles guilib source file(s) using NDK]

http://wlan-lj.net/browser/trunk/meshapp/olsr/olsrd/Makefile [Top
level makefile for a huge C project that I compile into an ARM binary
for Android]
http://wlan-lj.net/browser/trunk/meshapp/olsr/olsrd/Makefile.inc
[Extension to the above GNU makefile]
http://wlan-lj.net/browser/trunk/meshapp/olsr/olsrd/make/Makefile.android
[Android-specific makefile, similar to the above but creates ARM
binary rather than static library]

It's ugly (and still a work in progress), but it works.

Hope this helps!

- Charles

Olivier Guilyardi

unread,
Jul 14, 2010, 8:43:59 AM7/14/10
to andro...@googlegroups.com
Ugly or not, this isn't NDK compliant to me. You are calling NDK gcc directly
and playing with CFLAGS/LDFLAGS, whereas you should let ndk-build handle this.

It works for you maybe, but it might fail on some current or future devices.

Olivier

Burhan Eyuboglu

unread,
Dec 18, 2014, 9:11:53 AM12/18/14
to andro...@googlegroups.com
Oliver,

Can I create Android.mk by reading Makefile file? Not makefile.am or makefile.in.
If not, why?
Do we have to create it by reading Makefile.am?



12 Temmuz 2010 Pazartesi 15:37:52 UTC+3 tarihinde Olivier Guilyardi yazdı:
Reply all
Reply to author
Forward
0 new messages