Linking and source code organization
In the previous recipes, we learned how to create basic wrappers that allow us to run our application on Android and Windows. However, we used an ad-hoc approach since the amount of source code was low and fit into a single file. We have to organize our project source files in a way suitable for building the code for larger projects in Windows and Android.
Getting ready
Recall the folder structure of the App3
project. We have the src
and jni
folders inside our App2
folder. The jni/Android.mk
, jni/Application.mk
, and build.xml
files specify the Android build process. To enable the Windows executable creation, we add a file named Makefile
, which references the main.cpp
file.
How to do it...
The following is the content of Makefile
:
CC = gcc all: $(CC) -o main.exe main.cpp -lgdi32 -lstdc++
The idea is that when we add more and more OS-independent logic, the code resides in .cpp
files, which do not reference any OS-specific headers or libraries. For the first few chapters, this simple framework that delegates frame rendering and event handling to portable OS-independent functions (OnDrawFrame()
, OnKeyUp()
and so on) is enough.
How it works...
All of our examples from the subsequent chapters are buildable for Windows from the command line using a single make all
command. Android native code is buildable with a single ndk-build
command. We will use this convention throughout the rest of the book.