完美编译运行PCRE on Windows , Solved the __imp__pcre_exec __imp__pcre_compile __imp__pcre_free Errors

写写英文吧,好长时间不写都有点不熟练了when I compile the following codes which test the pcre , I got the unreferenced error __imp__pcre_exec __imp__pcre_compile __imp__pcre_free Errors, my Codes are follows:
//packing pcre usual functions.

#ifndef _PCRE_H_
#define _PCRE_H_
#include 
#include 
#include 
#include 
using namespace std;

const int VECSIZE = 30;

struct MatchResult
{
	string name;
	vector value;
};

class Pcre
{
public:
	Pcre();
	~Pcre();

	//Add a regrex, pass in name and regrex
	int AddRule(const string &name, const string &patten);

	//clear all the regrex
	void ClearRules();

	//match all the regrex, also return all the string match to every regrex
	vector MatchAllRule(const char content[]);

private:
	const char *error;
	int erroffset;
	int ovector[VECSIZE];
	vector re_arr;
	vector patten_name;
};
#endif

Pcre.cpp

#include "Pcre.h"
#include 

Pcre::Pcre()
{
	re_arr.clear();
	patten_name.clear();
}

Pcre::~Pcre()
{
	for(int i=0; i Pcre::MatchAllRule(const char content[])
{
	vector result_arr;
	int length = strlen(content);
	char buf[512];
	for(int i=0; i= 0)
        	{
                	for(int j=0; j 0)
			result_arr.push_back(result);
	}
	return result_arr;
}

 Main.cpp

1>正在生成代码...
1>正在链接...
1>Pcre.obj : error LNK2001: 无法解析的外部符号 __imp__pcre_free
1>Pcre.obj : error LNK2001: 无法解析的外部符号 __imp__pcre_compile
1>Pcre.obj : error LNK2001: 无法解析的外部符号 __imp__pcre_exec
1>.\Debug/main.exe : fatal error LNK1120: 3 个无法解析的外部命令
1>生成日志保存在“file://E:\Test\Pcre-Test\Debug\BuildLog.htm”
1>main - 4 个错误,7 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

 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

try it ... successful !!!!


你可能感兴趣的:(程序相关,Linux知识)