Skip to content

How to compile a code using wiselib

vasilakis edited this page May 24, 2011 · 3 revisions

In this section we show how you can compile a source code using wiselib features.

Firstly download wiselib at your /home/username/ directory(or anywhere else).Also download and http://developer.android.com/sdk/ndk/index.html the Android NDK.

Wiselib makefiles that have to do with android are:
wiselib/trunk/applications/Makefile: The main makefile that is called when you type make android.
wiselib/trunk/applications/Makefile.local: File that declares(exports) all the necessary variables.
wiselib/trunk/applications/Makefile.android: Makefile actually calls the ndk-build script from the ndk folder.
wiselib/trunk/applications/Android.mk File that includes all the necessary files for compilation.

After setting up the wiselib you also have to declare at wiselib where the ndk folder. Open the wiselib/trunk/applications/Makefile.local file, go to the android section and declare the path.

On every android ndk application you create that uses wiselib components you must create a makefile as shown below:

#!/bin/bash

all: android

include /home/vasilakis/wiselib/trunk/applications/Makefile

As you see, this makefile just includes the wiselib's main makefile. As you apparently know, android ndk works with its own makefiles (the files that end at .mk). As a matter of fact, everything that you application needs(even the targeted cpu architecture arm or x86) you declare it at the Android.mk and Application.mk files.Application.mk is to describe which native 'modules' (i.e. static/shared libraries, arm or x86 cpu architecture) are needed by your application. Android.mk file is written to describe your sources to the build system.As a result, you have to add the wiselib files in your Android.mk file. As it metioned above, under the directory wiselib/trunk/applications/ there is an Android.mk file that does the job. All you have to do is to add this file relatively to your path.For example, if you build an application that uses a native file, "timerTest.cpp" under the directory $HOME/androidTest/jni/, after you include your source codes you add relatively wiselib's android.mk file as seen below.

# build file written to describe the C and C++ source files to the Android NDK
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)


LOCAL_MODULE    := timerTest
LOCAL_SRC_FILES := timerTest.cpp

include ../../wiselib/trunk/applications/Android.mk   #THIS LINE IS NEEDED BY NDK TO INCLUDE WISELIB MODULES

LOCAL_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_SHARED_LIBRARY)

Now if you type make android, ndk-build will be called(with paremeters clean, all and -B) from your directory and will build the library. The reason that you have to include wiselib's android.mk in a relative path is that in essence, build-ndk script is called from your working directory(actually from the directory in which an Android.mk file made the last change to LOCAL_PATH variable).