# libgnurx **Repository Path**: yikh/libgnurx ## Basic Information - **Project Name**: libgnurx - **Description**: GNU Regex for Windows 2.9 - **Primary Language**: Unknown - **License**: BSD-2-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-06-27 - **Last Updated**: 2024-06-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GNU regex 2.9 for Windows 最近我的一个跨平台项目遇到了一个问题:需要在MSVC下调用`linux`下才有正则表达式C接口(`regex.h`)。 我们知道`linux`上提供了C接口的正则表达式库(`regex.h`),但是在windows下MSVC并没有同样的`regex.h`. `linux`上的regex实现实际上是GNU提供的。如果找到对应的源码并且在win32下可编译,就可以解决问题。 循着这个思路我在这里([https://launchpad.net/gnuregex/+milestone/2.9](https://launchpad.net/gnuregex/+milestone/2.9))找到了GNU regex for win32源码。 因为这个源码是用`gcc`编译的使用了GNU扩展语法,所以如果直接用MSVC编译会报错,所以我做了一些修改,解决了在MSVC下编译问题,就可以在MSVC项目中使用了。 你可以直接把所有源码添加(测试代码除外)到自己的项目中使用,也直接可以如下说明使用[`NMakefile`](NMakefile)脚本`nmake` 编译出静态库再使用. ---- copy from [https://launchpad.net/gnuregex/+milestone/2.9](https://launchpad.net/gnuregex/+milestone/2.9), and modify for building with MSVC `regcomp`,`regerror`,`regexec` test pass. ## Build static library with MSVC nmake /f NMakefile ## Generated libraries |Library|Build Parameter|Build Type| |:--|:--|:--| |regex.lib|/MD /O2|Release| |regex_d.lib|/MDd /D DEBUG|Debug| |regex_mt.lib|/MT /O2|Release| |regex_mt_d.lib|/MTd /D DEBUG|Debug| ## Run test ```shell # build regex_test.c and run nmake /f NMakefile test # build gnuregex_test.c and run nmake /f NMakefile test2 # build rx_search_test.c and run nmake /f NMakefile test3 ``` need run in `Visual Studio Developer Command Prompt` ![](images/msvc-shell0.png) ![](images/msvc-shell1.png) ![](images/msvc-shell2.png) ## Conan Build 支持Conan包安装编译: ```bash $ cd libgnurx # 编译 $ conan create . # 上传libgnuex包到远程仓库 $ conan upload . -r ${repo} ```