windows平台手動編譯pcre

來源:互聯網
上載者:User

將 config.h.generic 重新命名為 config.h
設定其中的 HAVE_BCOPY 參數為 0 (因為windows平台無bcopy()函數)
重新命名 pcre.h.generic 為 pcre.h.
重新命名 pcre_chartables.c.dist 為 pcre_chartables.c.
編譯 dftables.c 成可執行檔,要加入參數 -DHAVE_CONFIG_H,以便匯入 config.h 檔案中的設定
/* 重新命名 pcre_chartables.c.dist 為 pcre_chartables.c */
運行編譯的可執行檔 dftables.exe ,參數為 pcre_chartables.c
即 dftables.exe pcre_chartables.c
建立工程,包含下列檔案,編譯成lib檔案即可
pcre_internal.h
ucp.h
ucpinternal.h
ucptable.h
pcre_chartables.c
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_maketables.c
pcre_newline.c
pcre_ord2utf8.c
pcre_refcount.c
pcre_study.c
pcre_tables.c
pcre_try_flipped.c
pcre_ucp_searchfuncs.c
pcre_valid_utf8.c
pcre_version.c
pcre_xclass.c

這樣就可以產生 libpcre.a 檔案了 (vc,bcc產生的是pcre.lib,大同小異)

2、使用產生的 libpcre.a (靜態連結庫)

在你的程式中添加:

#define PCRE_STATIC // 開啟靜態連結庫支援(一定要添加該行,否則無法使用靜態連結庫)
#include "pcre.h" // PCRE標頭檔
並且添加 libpcre.a 到工程中,然後就可以在程式中使用PCRE函數了:)

編譯選項 添加 /MT ,無標頭檔先行編譯.

3、使用產生的 libpcre-0.dll 和 libpcre.dll.a (動態連結程式庫)

在你的程式中添加:

#include "pcre.h" // PCRE標頭檔

並且添加 libpcre.dll.a 到工程中,然後就可以在程式中使用PCRE函數了:)

================================================================================

命令列下的批處理解決方案 .如果已經下載,可以不用第一行.

goto START

首先確保控制台環境中有:
1、VC6命令列編譯環境
2、wget.exe、unzip.exe、sed.exe、mv.exe
然後執行這個批次檔,就可以得到VC版本的pcr.lib。

:START
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.zip
unzip pcre-7.7.zip
cd pcre-7.7
sed -e "s/#define HAVE_BCOPY 1/#define HAVE_BCOPY 0/g" config.h.generic > config.h
mv pcre.h.generic pcre.h
mv pcre_chartables.c.dist pcre_chartables.c
cl -MD -DHAVE_CONFIG_H dftables.c
dftables.exe pcre_chartables.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_chartables.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_compile.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_config.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_dfa_exec.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_exec.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_fullinfo.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_get.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_globals.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_info.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_maketables.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_newline.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_ord2utf8.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_refcount.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_study.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_tables.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_try_flipped.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_ucp_searchfuncs.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_valid_utf8.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_version.c
cl -O1 -MD -DHAVE_CONFIG_H -c pcre_xclass.c
lib -out:libpcr.lib pcre_chartables.obj pcre_compile.obj pcre_config.obj pcre_dfa_exec.obj pcre_exec.obj pcre_fullinfo.obj pcre_get.obj pcre_globals.obj pcre_info.obj pcre_maketables.obj pcre_newline.obj pcre_ord2utf8.obj pcre_refcount.obj pcre_study.obj pcre_tables.obj
pcre_try_flipped.obj pcre_ucp_searchfuncs.obj pcre_valid_utf8.obj pcre_version.obj pcre_xclass.obj

這樣就出來了: pcre.h + libpcr.lib

==============================================================================

最近使用VC編譯了一下她的原始碼,其實步驟很簡單, 如下

1 一些源檔案改名
config.h.generic 改名為 config.h (注意裡面的配置)
pcre.h.generic 改名為 pcre.h
pcre_chartables.c.dist 改名為 pcre_chartables.c

2 建立VC工程
建立一個VC的DLL工程,去掉原有的包含檔案
將PCRE的所有pcre_*.c都加進去, pcre後面沒有_的不要加, 尾碼名是.cc的不要加
可以參考上面的.還有.h 檔案也是要的.

3 修改工程設定

增加工程先行編譯宏 HAVE_CONFIG_H
不使用先行編譯頭 Not Using Precompiled Headers
編譯選項 添加 /MT

OK 完成以上三步,就可以在 VC 上編譯通過了。

4 編譯結果
使用時只需要編譯出來的 .DLL .Lib 和 原始碼目錄的 pcre.h

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.