Regexpcre在Android下的移植

來源:互聯網
上載者:User

因為項目需要在android的NDK開發中使用pcreRegex庫,而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.hLOCAL_COPY_HEADERS_TO := libpcreLOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_HLOCAL_MODULE := libpcreLOCAL_MODULE_CLASS := STATIC_LIBRARIESLOCAL_PRELINK_MODULE := falseinclude $(BUILD_STATIC_LIBRARY)###### Build pcregrep###include $(CLEAR_VARS)LOCAL_MODULE := pcregrepLOCAL_SRC_FILES := pcregrep.cLOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_HLOCAL_STATIC_LIBRARIES := libpcreinclude $(BUILD_EXECUTABLE)

4. cd 到 android的源碼樹的根目錄下,輸入命令:

. build/envsetup.sh

chooseproduct

mmm external/pcre

從下面的log可以看到產生了libpcre.a庫:

make: Entering directory `/home/braincol/workspace/android/android_build/android_sdk_froyo'

Header: out/target/product/generic/obj/include/libpcre/pcre.h

target thumb C: pcregrep <= external/pcre/pcregrep.c

target thumb C: libpcre <= external/pcre/pcre_compile.c

target thumb C: libpcre <= external/pcre/pcre_config.c

target thumb C: libpcre <= external/pcre/pcre_dfa_exec.c

target thumb C: libpcre <= external/pcre/pcre_exec.c

target thumb C: libpcre <= external/pcre/pcre_fullinfo.c

target thumb C: libpcre <= external/pcre/pcre_get.c

target thumb C: libpcre <= external/pcre/pcre_globals.c

target thumb C: libpcre <= external/pcre/pcre_info.c

target thumb C: libpcre <= external/pcre/pcre_maketables.c

target thumb C: libpcre <= external/pcre/pcre_newline.c

target thumb C: libpcre <= external/pcre/pcre_ord2utf8.c

target thumb C: libpcre <= external/pcre/pcre_refcount.c

target thumb C: libpcre <= external/pcre/pcre_study.c

target thumb C: libpcre <= external/pcre/pcre_tables.c

target thumb C: libpcre <= external/pcre/pcre_try_flipped.c

target thumb C: libpcre <= external/pcre/pcre_ucd.c

target thumb C: libpcre <= external/pcre/pcre_valid_utf8.c

target thumb C: libpcre <= external/pcre/pcre_version.c

target thumb C: libpcre <= external/pcre/pcre_xclass.c

target thumb C: libpcre <= external/pcre/pcre_chartables.c

target StaticLib: libpcre (out/target/product/generic/obj/STATIC_LIBRARIES/libpcre_intermediates/libpcre.a)

target Executable: pcregrep (out/target/product/generic/obj/EXECUTABLES/pcregrep_intermediates/LINKED/pcregrep)

target Non-prelinked: pcregrep (out/target/product/generic/symbols/system/bin/pcregrep)

target Strip: pcregrep (out/target/product/generic/obj/EXECUTABLES/pcregrep_intermediates/pcregrep)

Install: out/target/product/generic/system/bin/pcregrep

make: Leaving directory `/home/braincol/workspace/android/android_build/android_sdk_froyo'

 

然後只要把libpcre.a庫和標頭檔pcre.h拷貝到你的android應用工程中,然後就可以在ndk中使用這個pcre庫了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.