Android compiling environment-compile the helloworld module of native C

Source: Internet
Author: User
(1) Android compiling environment
-Compile the helloworld module of native C


(1) Source compilation environment
[1]

Android compiling environmentUnlike normal compiling environments, makefile files are available only in the top-level directory, while each other component uses a unified standardAndroid. mk.
Android. mkThe file itself is relatively simple, but it is not the makefile we are familiar with, but a lot of processing through the android compilation system. Therefore, it is still complicated to understand the links, however, the advantage of this method is to write a newAndroid. mkTo add a new component for Android. Compiling Java programs can be completed directly using the eclipse integrated environment, which will not be repeated here. We mainly describe C/C ++. The following uses a small example to illustrate how to add a C program Hello World: 1 in Android.
Create the hello directory under the $ (your_android)/Development Directory. $ (your_android) indicates the directory where the android source code is located.

-# Mkdir $(your_android)/development/hello2.
Write the hello. c file in the $ (your_android)/development/Hello/directory. The content of Hello. C is of course the classic helloworld program:

# Include <stdio. h>

Int main ()
{
Printf ("Hello world! \ N "); Return 0;

}

3.
Write the Android. mk file in the $ (your_android)/development/Hello/directory. This is the standard name of Android makefile. Do not change it. For the format and content of the android. mk file, refer to other existing Android. mk files. The content of the android. mk file for the helloworld program is as follows:
Local_path: = $ (call my-DIR) include $ (clear_vars) local_module_tags: = optional# Added by the editor according to the compilation promptLocal_src_files: = \ hello. clocal_module: = helloworldinclude $ (build_executable)
Note that the above local_src_files are used to specify the source file. local_module specifies the name of the module to be compiled, which will be used in the next step. include $ (build_executable) indicates that the file will be compiled into an executable file, if you want to compile it into a dynamic library, you can use build_shared_library, which can be in $ (your_android)/build/CORE/config. mk. 4.
Go back to the top-level directory of the android source code for compilation:
# Cd $ (your_android) & make helloworld
Note that the target name helloworld in make helloworld is the module name specified by local_module In the android. mk File above. The compilation result is as follows:
Target thumb C: helloworld <= Development/Hello/hello. ctarget executable: helloworld (Out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld) target non-prelinked: helloworld (Out/target/product/generic/symbols/system/bin/helloworld) Target Strip: helloworld (Out/target/product/generic/obj/executables/helloworld_intermediates/helloworld) install: Out/target/product/generic/system/bin/helloworld
5. as shown in the preceding compilation result, the compiled executable file is stored in the out/target/product/generic/system/bin/helloworld file and transmitted to the simulator through "ADB push, then, log on to the simulator terminal through "ADB shell", and you will be able to execute

Editor's note: ADB push hello Dev/Hello
Pay attention to the following path/, and do not push it to another directory. Otherwise, the permission prompt will be executed.
Denied.

ADB shell chmod 777 DEV/Hello

ADB Shell
CD Dev
./Hello output result!


Q: Is it so easy to write an android. mk file in a library? For example, porting the iconv Library

[1]
See
Http://zhubin215130.iteye.com/blog/654145

Attachment:
Android compiling environment-compile native c's helloworld).rar (7 k) Downloads: 0
[Delete]

 

Original text in http://www.bangchui.org/read.php? Tid = 21850

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.