正则表达式pcre在Android下的移植
http://www.cnblogs.com/hibraincol/archive/2011/10/15/2213714.html
#---------------------------------------------------------------------------------
然后只要把libpcre.a库和头文件pcre.h拷贝到你的android应用工程中,然后就可以在ndk中使用这个pcre库了。
阅读(39) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
因为项目需要在android的NDK开发中使用pcre正则表达式库,而android系统中并没有自带该库,所以就得另外移植了, 下面是移植的详细步骤:
1. 下载pcre源码,可以到http://sourceforge.net/projects/pcre/下载源码。
我这里使用的是pcre-7.8.tar.gz 。
2. 将pcre-7.8 的源码拷贝至android源码树下的external/pcre目录下。
3. 将下面的Android.mk文件拷贝到external/pcre目录下。
Android.mk:
#---------------------------------------------------------------------------------#
# Android makefile for libpcre
#
# This makefile generates libpcre.a, pcregrep and pcre.h ONLY.
# It should be amended to build libpcreposix.a, libpcrecpp.a
# and tests.
LOCAL_PATH := $(call my-
dir
)
###
### Build libpcre.a and pcre.h
###
include $(CLEAR_VARS)
#step 1:
# to generate the files config.h pcre.h pcre_chartables.c
#
GEN := $(LOCAL_PATH)
/config
.h
$(GEN): $(LOCAL_PATH)
/config
.h.generic
$(hide)
cp
$(LOCAL_PATH)
/config
.h.generic $@
LOCAL_GENERATED_SOURCES += $(GEN)
GEN := $(LOCAL_PATH)
/pcre
.h
$(GEN): $(LOCAL_PATH)
/pcre
.h.generic
$(hide)
cp
$(LOCAL_PATH)
/pcre
.h.generic $@
LOCAL_GENERATED_SOURCES += $(GEN)
GEN := $(LOCAL_PATH)
/pcre_chartables
.c
$(GEN): $(LOCAL_PATH)
/pcre_chartables
.c.dist
$(hide)
cp
$(LOCAL_PATH)
/pcre_chartables
.c.dist $@
LOCAL_GENERATED_SOURCES += $(GEN)
#step 2:
#clear the vars generated by the step 1
#
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
pcre_compile.c \
pcre_config.c \
pcre_dfa_exec.c \
pcre_exec.c \
pcre_fullinfo.c \
pcre_get.c \
pcre_globals.c \
pcre_info.c \
pcre_internal.h \
pcre_maketables.c \
pcre_newline.c \
pcre_ord2utf8.c \
pcre_refcount.c \
pcre_study.c \
pcre_tables.c \
pcre_try_flipped.c \
pcre_ucd.c \
pcre_valid_utf8.c \
pcre_version.c \
pcre_xclass.c \
pcre_chartables.c \
ucp.h \
pcre.h \
config.h
#copy the pcre.h to out/target/product/generic/obj/include/libpcre
#
LOCAL_COPY_HEADERS := pcre.h
LOCAL_COPY_HEADERS_TO := libpcre
LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H
LOCAL_MODULE := libpcre
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_PRELINK_MODULE :=
false
include $(BUILD_STATIC_LIBRARY)
###
### Build pcregrep
###
include $(CLEAR_VARS)
LOCAL_MODULE := pcregrep
LOCAL_SRC_FILES := pcregrep.c
LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H
LOCAL_STATIC_LIBRARIES := libpcre
include $(BUILD_EXECUTABLE)
4. cd 到 android的源码树的根目录下,输入命令:
. build/envsetup.sh
chooseproduct
mmm external/pcre
从下面的log可以看到生成了libpcre.a库:
然后只要把libpcre.a库和头文件pcre.h拷贝到你的android应用工程中,然后就可以在ndk中使用这个pcre库了。
相关热门文章
给主人留下些什么吧!~~
评论热议