加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

RE2正则表达式库的Windows移植

发布时间:2020-12-14 02:06:37 所属栏目:百科 来源:网络整理
导读:RE2库的Windows移植过程如下: 1.从http://code.google.com/p/re2/downloads/list下载最新RE2库(re2-20130802.tgz)。 2.解压到当前本地硬盘上,生成一个re目录; 3.打开VS 2008开发环境,在re目录中创建一个新的静态库工程,命名为re2; 4.从网上(http://w

RE2库的Windows移植过程如下:

1.从http://code.google.com/p/re2/downloads/list下载最新RE2库(re2-20130802.tgz)。

2.解压到当前本地硬盘上,生成一个re目录;

3.打开VS 2008开发环境,在re目录中创建一个新的静态库工程,命名为re2;

4.从网上(http://www.sourceware.org/pthreads-win32/)下载pthread-win32库,在解压的re2目录下创建一个win32目录,把pthread-win32头文件放置该目录中,把pthreadVC2.lib和pthreadVC2.dll放入到lib目录中。

从网上http://code.google.com/p/msinttypes/下载msinttypes-r26.zip 把其中stdint.h解压到win32目录下。

5.在创建的re2工程中添加re2目录中re2和util下的全部的cc源代码。

6.打开re2工程属性对话框,设置如下:

1) Configure选择AllConfigurations;

2)General中OutputDirectory设置为.lib,Intermediate Directory设置为.objDebug|Release(需要在Debug和Release下分别设置);

3) C/C++中General下AdditionalInclude Directories设置./;./win32;

Advanced下设置DisableSpecific Warnings为4244;4996;4800;4805;4018

在Preprocesssor下PreprocessorDefinitions添加COMPILER_MSVC(Debug和Release分别添加);

4)Librarian中General下Additional Dependencies添加pthreadVC2.lib,AdditionalLibrary Directories添加./lib,Debug模式下Output File设置为$(OutDir)$(ProjectName)d.lib。

7.Debug下编译re2工程,修改编译错误的地方。

0)warningC4819: The file contains a character that cannot be represented in the currentcode page (936). Save the file in Unicode format to prevent data loss

打开unicode_casefold.h头文件,点击File/Advanced SaveOptions,Encoding选择Unicode – Codepage 1200,点击“OK”。

1)fatalerror C1083: Cannot open include file: 'sys/time.h': No such file or directory

在win32目录下创建sys目录,在sys目录中创建一个空的time.h头文件。

2)errorC2039: 'unordered_set' : is not a member of 'std'

打开util.h文件,52行修改为usingstd::tr1::unordered_set;

3)fatal error C1083: Cannot open include file: 'unistd.h': No suchfile or directory

在win32目录下创建unistd.h头文件,加入下面两行:

#include <io.h>

#define write _write

4)errorC3861: 'strtoll': identifier not found; 'strtoull': identifier not found;'strtof': identifier not found

打开re2.cc文件,在第21行下面添加下面几个宏定义:

#if defined(_MSC_VER)

#define strtoll _strtoi64

#define strtoull _strtoui64

#define strtof strtod

#endif

5)error C3861:'snprintf': identifier not found

打开prefilter_tree.cc文件,在14行下面添加下面宏定义:

#if defined(_MSC_VER)

#define snprintf _snprintf

#endif

6)valgrind.cc(12): error C2143: syntax error : missing ')' before '{'

打开valgrind.cc,在第12行添加下面几行:

#if defined(_MSC_VER)

return 0;

#else

return RUNNING_ON_VALGRIND;

#endif

7)thread.cc(11): error C2679: binary '=' : no operator found which takes

打开thread.cc文件,直接注释掉pid_ = 0;因为pthread-win32的pthread_t是一个结构。

8)从工程中删除remove掉test.cc、pcre.cc、benchmark.cc和sparse_array_test.cc文件。

9)stringprintf.cc(17) : error C3861: 'va_copy': identifier not found

打开stringprintf.cc文件,在第6行下添加下面几行:

#if defined(_MSC_VER)

#define va_copy(dest,src) (dest = src)

#endif

10)stringpiece.cc(11): error C2039: '_write' : is not a member of 'std

打开stringpiece.cc文件,在第9行添加#undefwrite。

11)打开re2.cc文件,把RE2::Init成员函数中entire_regexp_= Regexp::Parse(的参数pattern_修改为pattern(大约198行左右)。

12)打开stringpiece.h头文件,在第26行添加#undefmin

13)编译成功,在lib目录下生成re2d.lib、re2.lib两个静态库。此外,re2库用到的头文件在re2/re2目录下,包括filtered_re2.h、re2.h、set.h、stringpiece.h和variadic_function.h。

注意:必须把上面头文件放置在re2目录下,比如:放置到include/re2下。

注意:warningC4819: The file contains a character that cannot be represented in the currentcode page (936). Save the file in Unicode format to prevent data loss

解决方法:打开出现warning的文件,Ctrl+A全选,然后在文件菜单:file->advancedsave options ,在弹出的选项中选择新的编码方式为:UNICODE codepage 1200 ,点击确定

注意:VC生成静态库release版比debug版库文件尺寸更大的原因:得出的结论是,此问题是由VS的Build选项中Optimization项下的Whole Program Opeimization选项不同设置引起:Debug版的此选项缺省设成No,而Release版的此选项缺省设成Enablelink-time code generation (/GL)。由于静态库并不进行链接,而全局优化要等到链接时,所以release版产生的库文件就要比debug版的大上不少了。

RE2 Windows移植的源代码下载地址:http://code.google.com/p/re2/issues/detail?id=89。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读