(0)从http://gnuwin32.sourceforge.net/packages/pcre.htm (pcre windows)下下载最新的windows平台源代码pcre-7.0-src.zip,不要选择开发包以及bin文件,由于编译器(bcc以及交叉编译器)的差异,会导致这些不同后缀名得库用不了,浪费时间。
(1) Copy or rename the file config.h.in asconfig.h, and change the macros that
define HAVE_STRERROR and HAVE_MEMMOVE to definethem as 1 rather than 0.
Unfortunately, because of the way Unix autoconfworks, the default setting has
to be 0. You may also want to make changes toother macros in config.h. In
particular, if you want to force a specific valuefor newline, you can define
the NEWLINE macro. The default is to use ‘\n‘,thereby using whatever value
your compiler gives to ‘\n‘.
rem MarkTetrode‘s commands
copyconfig.h.in config.h
rem Usewrite, because notepad cannot handle UNIX files. Change values.
writeconfig.h
将config.h.in文件中的 #define HAVE_STRERROR 0和#defineHAVE_MEMMOVE 0改成 #define HAVE_STRERROR 1和#define HAVE_MEMMOVE 1后复制为config.h
(2) Compile dftables.c as a stand-alone program,and then run it with
the single argument "pcre_chartables.c".This generates a set of standard
character tables and writes them to that file.
rem MarkTetrode‘s commands
remCompile & run
cl-DSUPPORT_UTF8 -DSUPPORT_UCP dftables.c
dftables.exe pcre_chartables.c
直接在src目录下,用vc6.0代开dftables.c,编译生成一个项目,然后在 工程-》设置-》C/C++-》常规-》预处理程序定义中,加入“,SUPPORT_UTF8,DSUPPORT_UCP”,编译成功,然后用cmd来执行dftables.exepcre_chartables.c。
(3) Compile the following source files:
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
and link them all together into an object libraryin whichever form your system
keeps such libraries. This is the pcre C library.If your system has static and
shared libraries, you may have to do this once foreach type.
rem Thesecomments are out-of-date, referring to a previous release which
rem hadfewer source files. Replace with the file names from above.
rem MarkTetrode‘s commands, for a static library
remCompile & lib
cl-DSUPPORT_UTF8 -DSUPPORT_UCP -DPOSIX_MALLOC_THRESHOLD=10 -DPCRE_STATIC /c maketables.c get.c study.c pcre.c
lib/OUT:pcre.lib maketables.obj get.obj study.obj pcre.obj
搜索所有的c文件,从src中拷出来,放在单独的文件夹下,并删除不需要的c文件。
所有所有的h文件,从src中拷出来,放在同一个单独的文件夹下。
新建一个空白静态链接库工程,添加所有文件到工程中,然后在 工程-》设置-》C/C++-》常规-》预处理程序定义 中,加入“,SUPPORT_UTF8,DSUPPORT_UCP,POSIX_MALLOC_THRESHOLD=10,PCRE_STATIC”,其中PCRE_STATIC是必须的,否则后面exe link 库会出现undefined sympol_smp_等找不到函数的问题。
在编译连接的时候,需要添加另外一个ucptable.c和pcre_printint.src,然后编译成功。
(4) Similarly, compile pcreposix.c and link it (onits own) as the pcreposix
library.
rem MarkTetrode‘s commands, for a static library
remCompile & lib
cl-DSUPPORT_UTF8 -DSUPPORT_UCP -DPOSIX_MALLOC_THRESHOLD=10 -DPCRE_STATIC /c pcreposix.c
lib/OUT:pcreposix.lib pcreposix.obj
将pcreposix.c拷贝到单独的文件夹下,将所有h文件拷贝在同一个文件夹下,创建空白静态库工程,设置同样的预定义指令,然后编译成功。
(5) Compile the test program pcretest.c. Thisneeds the functions in the
pcre and pcreposix libraries when linking.
rem MarkTetrode‘s commands
remcompile & link
cl -MD/F0x400000 pcretest.c pcre.lib pcreposix.lib
将pcretest.c 和所有的h文件拷贝到单独文件夹下,然后创建空白console应用,然后 工具-》选项-》目录-》库路径,设置pcre.lib和posixpcre.lib的路径,然后在 工程-》设置-》对象/库模块 中 加入pcre.lib pcreposix.lib,最后关键的是工程-》设置-》代码生成-》使用运行时库-》多线程DLL,也就是将工程选项中添加/MD ,最后编译成功。
(6)随意在网上找个例子,同样注意要设置/MD,均可编译运行成功。
High Points
(1)useful url(pcre静态库):根据src下的NON-UNIX-USE将两个库勉强编译出来,根据此贴才终于将连接库函数失败(nresolved external symbol_pcre_free)得到提醒,才终于连接成功。
http://topic.csdn.net/u/20110504/15/3e7bb67a-79de-4eb3-9aba-60136dc6ce12.html
(2)compile two libraries -DPCRE_STATIC
(3)compile exe -MD
(4)一个使用实例(PCRE函数简介和使用示例)
http://blog.csdn.net/sulliy/article/details/6247155
原文:http://www.cnblogs.com/dancheblog/p/3528298.html