官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 阜新市| 玛曲县| 马尔康县| 寻乌县| 吴川市| 财经| 福清市| 焦作市| 谷城县| 灌阳县| 浦北县| 博湖县| 西城区| 彰武县| 平凉市| 林芝县| 怀集县| 习水县| 茂名市| 江源县| 安康市| 永昌县| 通江县| 邯郸县| 化隆| 买车| 那坡县| 积石山| 平邑县| 台湾省| 茌平县| 财经| 遂平县| 措美县| 鹤壁市| 乌什县| 金坛市| 鲁甸县| 阿拉善左旗| 永靖县| 双辽市|