使用NDK开发C/C++项目规则(ZT)

来源:互联网 发布:小维淘宝店模特nana 编辑:程序博客网 时间:2024/05/22 04:39
使用NDK开发C/C++项目规则

 

<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}h3{mso-style-next:正文;margin-top:13.0pt;margin-right:0cm;margin-bottom:13.0pt;margin-left:0cm;text-align:justify;text-justify:inter-ideograph;line-height:173%;mso-pagination:lines-together;page-break-after:avoid;mso-outline-level:3;font-size:16.0pt;font-family:"Times New Roman";mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:595.3pt 841.9pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:42.55pt;mso-footer-margin:49.6pt;mso-paper-source:0;layout-grid:15.6pt;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:423304355;mso-list-type:hybrid;mso-list-template-ids:872588632 -907124490 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l0:level1{mso-level-text:%1.;mso-level-tab-stop:39.0pt;mso-level-number-position:left;margin-left:39.0pt;text-indent:-18.0pt;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}--> 为使更多朋友能更容易学会使用NDK开发C/C++ 程序,特写此贴,希望能帮的上大家。

    使用NDK开发C/C++项目需注意以下几点规则:

NDK工具原目录规则;
    在NDK上自建目录及文件规则;

NDK工具的Make File规则;
   
NDK工具的编译规则;

1.  
NDK工具的目录规则
apps          
# java项目目录、编译启动文件存放各项目目录中
#
最终编译结果将从out目录中拷贝一份到apps目录下的libs 目录中
build          #
编译环境目录
docs           #
文档目录
GNUmakefile    # makefile
启始文件
out           
# 编译生成后存放目录
README.TXT     # readme
说明
sources       
# C++项目目录

2.  
自建目录及文件规则
apps/<
项目名>                    # Java 项目
sources/<
项目名>                 # C++ 项目
apps/<
项目名>/Application.mk     # 启动编译项目列表 (必须有此文件)
apps/<
项目名>/default.properties # android 编译版本 (必须有此文件)

sources/<项目名>/Android.mk      # 此文件会寻找当前目录下所有子目录中的Android.mk文件

sources/<项目名>/<子项目>/Android.mk       # 编译子项目的makefile(必须有此文件)

 

3.   NDK 工具的Make File规则

创建文件 apps/<项目名>/default.properties

~/android-ndk-1.5_r1/apps/<项目名> $ gvim default.properties

### apps/<项目名>/default.properties ###

# 这里指定使用 android-3是指 android sdk 1.5 版本

target=android-3

 

创建文件apps/<项目名>/Application.mk

~/android-ndk-1.5_r1/apps/<项目名>  $ gvim Application.mk

### apps/<项目名>/Application.mk ###

APP_PROJECT_PATH := $(call my-dir)

#########################################################
# 子项目输出名列表

#########################################################
# 是每一个 sources/<项目名>/的所有子项目中Android.mk指定的输出名

APP_MODULES := <子项目输出名列表>

 

建立sources/<项目名>/Android.mk文件

~/android-ndk-1.5_r1/sources/<项目名> $ gvim Android.mk

### sources/project_test/Android.mk ###

# 寻找当前目录下的所有子目录中的Android.mk

include $(call all-subdir-makefiles)

    

建立sources/<项目名>/<子项目>/Android.mk文件

~/android-ndk-1.5_r1/sources/<项目名>/<子项目> $ gvim Android.mk

### sources/<项目名>/<子项目>/Android.mk ###

 

#########################################################
# 进入当前目录并取得当前目录的路径

#########################################################
# 其结果为: ~/android-ndk-1.5_r1/sources/<项目名>/<子项目>

LOCAL_PATH:= $(call my-dir)

 

#########################################################

# 清除NDK全局变量

#########################################################
include $(CLEAR_VARS)

 

#########################################################
# 项目需要编译源文件列表

#########################################################
LOCAL_SRC_FILES:=

 

#########################################################
# 项目需要的.h头文件目录列表

#########################################################
LOCAL_CFLAGS :=

 

#########################################################

# 项目需要的链接自编译出的.so 文件列表

#########################################################

LOCAL_SHARED_LIBRARIES :=

 

#########################################################
# 项目需要的链接非自编译出的.so文件目录及列表

#########################################################
LOCAL_LDLIBS :=

 

#########################################################
#
在执行此Android.mk 文件时,显示指定的变量信息

#########################################################
#
如无需显示则可在之前加“#”符号

# 此次则显示 LOCAL_SRC_FILE变量内容在控制台上

$(info $(LOCAL_SRC_FILES))

 

#########################################################
#
子项目编译出输文件名

#########################################################
LOCAL_MODULE :=
<子项目输出名>

 

#########################################################
# 项目编译出输引用文件名,编译成哪种文件,

#########################################################
# BUILD_EXECUTABLE 是指.bin二进制执行文件

# BUILD_SHARED_LIBRARY 是指.so 动态库文件

# BUILD_STATIC_LIBRARY 是指.a 静态库文件

# 例如 输出二进制执行文件

# include $(BUILD_EXECUTABLE)

include $(<项目编译出输文引用件名>)

 

######################################################################
#
注:上以所有*.mk文件中的 “XXX := ”这样的变量赋值操作格式如下:   #

# 每一个*.c/*.cpp 都使用空格分开,如果换行,则用 /               #

# 例如同行 : LOCAL_SRC_FILES := a.c b.cpp                            #

# 例如换行 : LOCAL_SRC_FILES := a.c /                                #

#                                b.cpp                               #

######################################################################

 
4.   NDK 工具的编译规则
# 技巧:强制重新编译,则在最后加“ -B”,注意减号前有空格
<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->~/android-ndk-1.5_r1 $ make APP=<项目名>


By Guilh

原创粉丝点击