项目编译报出如下错误:

Pcre.obj:error LNK2001:无法解析的外部符号 __imp__pcre_free
Pcre.obj:error LNK2001:无法解析的外部符号 __imp__pcre_compile
Pcre.obj:error LNK2001:无法解析的外部符号 __imp__pcre_exec

解决办法是在头文件的最开头加上宏定义#define PCRE_STATIC

疑问:为什么必须在其他#include之前呢?

请看pcre.h中48-66行

/* When an application links to a PCRE DLL in Windows, the symbols that are
imported have to be identified as such. When building PCRE, the appropriate
export setting is defined in pcre_internal.h, which includes this file. So we
don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */

#if defined(_WIN32) && !defined(PCRE_STATIC)
#  ifndef PCRE_EXP_DECL
#    define PCRE_EXP_DECL  extern __declspec(dllimport)
#  endif
#  ifdef __cplusplus
#    ifndef PCRECPP_EXP_DECL
#      define PCRECPP_EXP_DECL  extern __declspec(dllimport)
#    endif
#    ifndef PCRECPP_EXP_DEFN
#      define PCRECPP_EXP_DEFN  __declspec(dllimport)
#    endif
#  endif
#endif

参考:

Google it , I found the thread about the error, a comment gives the solutions:
Building under Windows:
If you want to statically link this program against a non-dll .a file, you must
define PCRE_STATIC before including pcre.h, otherwise the pcre_malloc() and
pcre_free() exported functions will be declared __declspec(dllimport), with
unwanted results. So in this environment, uncomment the following line. */

//#define PCRE_STATIC

参考链接:http://www.xuebuyuan.com/659173.html