本文共 1376 字,大约阅读时间需要 4 分钟。
项目编译报出如下错误:
Pcre.obj:error LNK2001:无法解析的外部符号 __imp__pcre_freePcre.obj:error LNK2001:无法解析的外部符号 __imp__pcre_compilePcre.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 areimported have to be identified as such. When building PCRE, the appropriateexport setting is defined in pcre_internal.h, which includes this file. So wedon'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 mustdefine PCRE_STATIC before including pcre.h, otherwise the pcre_malloc() andpcre_free() exported functions will be declared __declspec(dllimport), withunwanted results. So in this environment, uncomment the following line. *///#define PCRE_STATIC
参考链接:
转载于:https://blog.51cto.com/13187574/2083977