Compiling native programs for Android

There is an excellent tutorial by Nirnimesh on how to compile native programs for Android here

Unfortunately things have changed a bit since last year when this post was written. Andy’s agcc script doesn’t work with the most recent Google NDK release 4B.

I have changed the script a little bit to address new path changes. The new script is available here

Make sure to add this to your path


where AndroidNDK is your NDK installation directory.

Hope this works for you.


  1. Aleix Said,

    August 23, 2010 @ 9:23 pm


  2. vlad Said,

    August 23, 2010 @ 9:28 pm

    No problemo.

    Actually, we have set-up a Google Code project with Jason Holt, check it out at

    That’ is going to be a new home for the script and related hacks.

  3. amal Said,

    September 6, 2010 @ 9:38 am

    I cross compiled the latest NDK and trying to build a c++ program.
    I have modified your agcc script accordingly, but get linker errors.
    In function `main’:
    helloworld.cpp:(.text.main+0×38): undefined reference to `std::basic_ostream<char, std::char_traits >& std::operator<< <std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const*)’
    helloworld.cpp:(.text.main+0×50): undefined reference to `std::basic_ostream<char, std::char_traits >::operator<<(std::basic_ostream<char, std::char_traits >& (*)(std::basic_ostream<char, std::char_traits >&))’
    helloworld.cpp:(.text.main+0×68): undefined reference to `std::cout’
    helloworld.cpp:(.text.main+0×70): undefined reference to `std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)’
    /tmp/ccibnqFX.o: In function `__static_initialization_and_destruction_0(int, int)’:
    helloworld.cpp:(.text._Z41__static_initialization_and_destruction_0ii+0x5c): undefined reference to `std::ios_base::Init::Init()’
    /tmp/ccibnqFX.o: In function `__tcf_0′:
    helloworld.cpp:(.text.__tcf_0+0×28): undefined reference to `std::ios_base::Init::~Init()’
    collect2: ld returned 1 exit status

    Request help

  4. vlad Said,

    September 6, 2010 @ 9:45 am

    Looks, like you forgot to attach C++ library. I am not sure if Android actually has one. I’ll try to look into it later this week.

  5. Radu Said,

    November 18, 2010 @ 3:00 am

    Hi Vlad, excellent work! I;ve used the agcc (the old version) myself alot.

    However, this version requires PERL.
    I’ve created a script, for those that don’t want to install Perl, so here is another approach on using the Android NDK to compile Native C applications:

Leave a Comment