Android NDK GCC 4.6 (Update) + Bug Fix

Now that GCC 4.6 has been made the default toolchain in the Android NDK there is no need to follow any special steps. Check out Android NDKr8b.

It has a known bug already.  The STANDALONE toolchain that some use build from the NDK incorrectly sets up the paths for C++ headers.  The fix is seen here on the bug report (https://android-review.googlesource.com/#/c/39878/).

In short:


mv $NDK_TOOLCHAIN/arm-linux-androideabi/include/c++/4.6 $NDK_TOOLCHAIN/arm-linux-androideabi/include/c++/4.6.x-google

Enjoy the extra C++11 features such as lambda and constexpr.

Android NDK Standalone GCC 4.6

Not entirely sure when Google started to include the GCC 4.6 sources.  I have first noticed it at the current NDK r8 when running the download-toolchain-sources.sh

You have to compile it yourself.  There are instructions out there but now that google is including it things have gotten easier.  These instructions only apply to Linux.  Specifically tested in Ubuntu 12.04.

  • sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl
  • Download NDK
  • Untar NDK to [SOME_LOCATION], using /opt/ndk/
  • Set NDK_ROOT=/opt/ndk/
  •  ./build/tools/download-toolchain-sources.sh src/
  • Download MPC 0.9
  • Move mpc tar to ./src/mpc/
  • ./build/tools/build-gcc.sh --gmp-version=4.3.2 --mpc-version=0.9 --mpfr-version=2.4.2 --binutils-version=2.21 $(pwd)/src $(pwd) arm-linux-androideabi-4.6
  • ./build/tools/build-gcc.sh --gmp-version=4.3.2 --mpc-version=0.9 --mpfr-version=2.4.2 --binutils-version=2.21 $(pwd)/src $(pwd) x86-4.6
  • ./build/tools/build-gcc.sh --gmp-version=4.3.2 --mpc-version=0.9 --mpfr-version=2.4.2 --binutils-version=2.21 $(pwd)/src $(pwd) mipsel-linux-android-4.6
  • (Patience)

Now you can generate a standalone toolchain for distribution:

  • ./build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.6 --platform=android-9 --install-dir=/opt/android-9_arm/
  • ./build/tools/make-standalone-toolchain.sh --toolchain=x86-4.6 --platform=android-9 --install-dir=/opt/android-9_x86/
  • ./build/tools/make-standalone-toolchain.sh --toolchain=mipsel-linux-android-4.6 --platform=android-9 --install-dir=/opt/android-9_mips/

Done.

Similar steps can be applied to MAC OS X however setting up the development environment is far more annoying.  I have a feeling this might be near impossible to pull off in Windows without jumping through major hoops.

Swap with no Temp Variable

When I used to TA for the University of Saskatchewan in our intro C/C++ first year classes I used to try and challenge the students sometimes.  When the assignment rolled out on sorting the students were instructed to swap two variables.  As brand new programmers sometimes something as simple as swapping two variables doesn’t leap out at you.  Of course we just teach them that you need a temp variable and mission accomplished.  Well I always offered bonus marks for anyone who could derive the variable swap with no temp variable.   Years pass, no student ever got back to me with the answer ( they obviously didn’t have Google Fu ).  I find myself writing a routine today that required a swap.  I still remembered the trick:

int main()
{

int x = 42;
int y = 51236;

printf(“X before swap = %d\n”, x);

x ^= y;
y ^= x;
x ^= y;

printf(“X after swap = %d\n”, x);

return 0;

}

XOR god mode and fairly easy to remember. X xor Y, Y xor X, X xor Y.  Useful for any POD that is expressed as bytes consistently across architectures.

Needless to say this is a fun trick to blow the minds of long time programmers.

Google’s Coding Style Guide

Regardless of personal preference you will often be forced to adapt to the coding style of someone else.  Generally this will be an enforced style at the company you work for.  Some see this as a minor annoyance.  I personally see this as important and practical.  It helps maintain code readability, this is important for new comers or looking back at your own code.  By making code more readable you also make it more understandable, this makes maintenance even easier.   Decision about style have more impact than arguments like whether braces should be on the same line.

The coding preference which most closely matched my habits turned out to be Google’s C++ Coding Guide.  This made most sense to me as I learned programming starting with C then C++.  In reality I started coding in BASIC on a Commodore 64 but that is a different story.

I find this style guide has a lot of good habits one can derive from it.

Google’s C++ Style Guide

There are some changes to the style I make, here are some important ones:

  • Class members are all prefixed with an underscore
  • Two spaces between functions implementations

Diablo 3 Homebrew

Not all homebrew has to be emulators.  Not all homebrew we talk about has to come from here.

A very interesting project has fired up over the past 3 weeks.  Starting on IRC as a small project and growing into a large organization over github.  Being that the Diablo 3 beta was leaked very early to the public a strong desire to play was fired up in many.  As with many games today and particularily games of the Diablo genre almost everything in the game requires a server to communicate with.  So for those unlucky few who got shafted on the beta invites and wish to indulge in some Diablo 3 sights check out Mooege.  It is a private server emulator for Diablo 3.  No it won’t be the real game, no you can’t do quests yet.  You can run around the Diablo 3 universe, kill random mobs you spawn for 9001 damage and play with some of the skills for each class.  Surely this is enough to satiate your desires for Diablo 3 or exacerbate them, until the release date that is.

See Mooege and read the FAQ for installation info.

Update: Mooege Forums

Halsafar