Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
Makefile | D | 03-May-2024 | 372 | 22 | 11 | |
Makefile.hello_cpp | D | 03-May-2024 | 401 | 22 | 11 | |
Makefile.lib | D | 03-May-2024 | 1 KiB | 32 | 15 | |
Makefile.uselib | D | 03-May-2024 | 558 | 24 | 12 | |
README | D | 03-May-2024 | 4.1 KiB | 136 | 101 | |
hello.c | D | 03-May-2024 | 123 | 8 | 6 | |
hello_cpp.cpp | D | 03-May-2024 | 270 | 23 | 18 | |
hello_cpp.h | D | 03-May-2024 | 135 | 13 | 10 | |
hellolibrary.c | D | 03-May-2024 | 252 | 11 | 6 | |
use_hellolibrary.c | D | 03-May-2024 | 172 | 10 | 6 |
README
1Building native code applications and libraries 2 3STEP 1 4Building an application. 5-------- 6 70) set the environment variable PREBUILT to point to the Android prebuilt directory 8 export PREBUILT=<path_to_android_src>/prebuilt/<platform> 9 10where you type in the actual path to the android source in place of <path_to_android_src> 11and the platform you are using instead of <platform>: either linux-x86 or darwin-x86 12 131) Test the pndk install by building the hello world sample application: 14 15 cd <your_pndk_base>/samples/sample 16 make clean 17 make 18 19The sample application uses hello.c to construct the hello binary, which you 20can load and run on the ARM device. To achieve proper runtime behavior, verify 21that: 22 * crtbegin_dynamic.o is the first linked object file 23 * crtend_android.o is last linked object. 24Both are set by the config.mk file in pndk/config. 25 262) Test that this works correctly by attaching your ARM-based device to the USB 27port and installing the application (hello) you just made by (in the commands 28below # is the ARM device's shell prompt): 29 30NOTE: need a development build so remount opens system permissions 31 32 adb remount 33 adb push hello system/app 34 adb shell 35 # cd system/app 36 # ./hello 37 Hello from the NDK; no user libraries. 38 # exit 39 403) You may also build the c++ binary hello_cpp.cpp into an application: 41 42 make -f Makefile.hello_cpp clean 43 make -f Makefile.hello_cpp hello_cpp 44 45This uses the hello_cpp.cpp and hello_cpp.h files to construct the hello_cpp 46binary application, which you can load and run on the ARM device. Note that 47we do not provide for C++ exceptions thus you must use the -fno-exceptions flag 48when compiling. 49 50 adb push hello_cpp system/app 51 adb shell 52 # cd system/app 53 # ./hello_cpp 54 C++ example printing message: Hello world! 55 # exit 56 57 58STEP 2 59Building and using a library 60------- 61 62Makefile.lib in pndk/sample shows how to make either a shared library or a 63static library from the hellolibrary.c source. The example makes the libraries 64libhello-shared.so and libhello-static.a . 65 66Makefile.uselib then shows how to make an application that links against either 67a shared or a static library. They examples shows how to build the two 68applications use_hellolibrary-so and use-hellolibrary-a from the source 69use_hellolibrary.c. 70 711) To make a shared library and an application that uses it: 72 73 make -f Makefile.lib clean 74 make -f Makefile.lib sharedlib 75 make -f Makefile.uselib clean 76 make -f Makefile.uselib use_hellolibrary-so 77 782) Copy the shared library libhello-shared.so to /system/lib (or the location 79in which shared libraries are found by the kernel on your ARM-based device.) 80 81 adb push libhello-shared.so system/lib 82 83You would not typically use the -shared or -static extensions in the filename, 84but the distinction is important in the case where a static and shared library 85are made in the same directory. Giving the files different names allows you to 86override the link defaults that default to a static library of the same name. 87 883) The application, use_hellolibrary-so, can now be tested by loading and 89running on the ARM device. 90 91 adb push use_hellolibrary-so /system/app 92 adb shell 93 # cd system/app 94 # ./use_hellolibrary-so 95 Library printing message: Hello from the NDK. 96 # exit 97 984) To make a static library: 99 100 make -f Makefile.lib clean 101 make -f Makefile.lib staticlib 102 make -f Makefile.uselib clean 103 make -f Makefile.uselib use_hellolibrary-a 104 1055) Test the application use_hellolibrary-a by loading and running it on the ARM 106device. 107 108 adb push use_hellolibrary-a system/app 109 adb shell 110 # cd system/app 111 # ./use_hellolibrary-a 112 Library printing message: Hello from the NDK. 113 # exit 114 115 116SUMMARY: 117--------- 118 119To make everything execute the following: 120 121make clean 122make 123make -f Makefile.lib clean 124make -f Makefile.lib 125make -f Makefile.uselib clean 126make -f Makefile.uselib 127make -f Makefile.hello_cpp clean 128make -f Makefile.hello_cpp hello_cpp 129 130 131You should have: 132 * The libraries libhello-static.a and libhello-shared.so built, the latter 133 ready for installation, 134 * The applications hello, use_hellolibrary-a, and use_hellolibrary-so 135 available for installation on the ARM device. 136