项目:http://www.monkey.org/~provos/crawl/
需要安装:libevent和Berkeley
先安装Berkeley
下载到:http://www.oracle.com/technology/software/products/berkeley-db/index.html
然后:tar xzvf db-4.7.25.tar.gz
比较简单的就是:
cd build_unix/
如果以gcc和g++编译的话,须执行#env CC=gcc CCC=g++ ../dist/configure,
编译.
../dist/configure –prefix=/opt/Berkeley
make
make install
最后:
#vi /etc/ld.so.conf并将berkeleyDB的lib路径加到该文件的最后一行,这样才能找到并加载它的库文件.ld.so.conf是什么东西?它就是系统动态链接库的配置文件。此文件内,存放着可被LINUX共享的动态链接库所在目录的名字(系统目录/lib,/usr/lib除外),各个目录名间以空白字符(空格,换行等)或冒号或逗号分隔。
成功后,测试一段代码是否争:代码为:
编译:
gcc test.c -ggdb -I /opt/Berkeley/include/ -L/opt/Berkeley/lib/ -ldb -lpthread -o test.out
从网上找到的测试代码:红色部分是修改的
#include <db.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h> //添加
/* DB的函数执行完成后,返回0代表成功,否则失败 */
void print_error(int ret)
{
if(ret != 0)
printf(”ERROR: %s”,db_strerror(ret));
}
/* 数据结构DBT在使用前,应首先初始化,否则编译可通过但运行时报参数错误 */
void init_DBT(DBT * key, DBT * data)
{
memset(key, 0, sizeof(DBT));
memset(data, 0, sizeof(DBT));
}
int main(){
DB *dbp;
DBT key, data;
u_int32_t flags;
int ret;
char *fruit = “apple”;
int number = 15;
typedef struct customer
{
int c_id;
char name[10];
char address[20];
int age;
} CUSTOMER;
CUSTOMER cust;
int key_cust_c_id = 1;
cust.c_id = 1;
strncpy(cust.name, “javer”, 9);
strncpy(cust.address, “chengdu”, 19);
cust.age = 32;
/* 首先创建数据库句柄 */
ret = db_create(&dbp, NULL, 0);
print_error(ret);
/* 创建数据库标志 */
flags = DB_CREATE;
/* 创建一个名为single.db的数据库,使用B+树访问算法,本段代码演示对简单数据类型的处理
* */
ret = dbp->open(dbp, NULL, “single.db”, NULL, DB_BTREE, flags, 0);
print_error(ret);
init_DBT(&key, &data);
/* 分别对关键字和数据赋值和规定长度
* */
key.data = fruit;
key.size = strlen(fruit) + 1;
data.data = &number;
data.size = sizeof(int);
/* 把记录写入数据库中,不允许覆盖关键字相同的记录
* */
ret = dbp->put(dbp, NULL, &key, &data,DB_NOOVERWRITE);
print_error(ret);
/* 手动把缓存中的数据刷新到硬盘文件中,实际上在关闭数据库时,数据会被自动刷新
* */
//dbp->sync();//注释掉没找到错误,注释掉后可以运行,原来的拷贝是中文错误
init_DBT(&key, &data);
key.data = fruit;
key.size = strlen(fruit) + 1;
/* 从数据库中查询关键字为apple的记录
* */
ret = dbp->get(dbp, NULL, &key, &data, 0);
print_error(ret);
/* 特别要注意数据结构DBT的字段data为void
* *型,所以在对data赋值和取值时,要做必要的类型转换。
* */
printf(”The number = %d”, *(int*)(data.data));
if(dbp != NULL)
dbp->close(dbp, 0);
ret = db_create(&dbp, NULL, 0);
print_error(ret);
flags = DB_CREATE;
/* 创建一个名为complex.db的数据库,使用HASH访问算法,本段代码演示对复杂数据结构的处理
* */
ret = dbp->open(dbp, NULL, “complex.db”, NULL, DB_HASH, flags, 0);
print_error(ret);
init_DBT(&key, &data);
key.size = sizeof(int);
key.data = &(cust.c_id);
data.size = sizeof(CUSTOMER);
data.data = &cust;
ret = dbp->put(dbp, NULL, &key, &data,DB_NOOVERWRITE);
print_error(ret);
memset(&cust, 0, sizeof(CUSTOMER));
key.size = sizeof(int);
key.data = &key_cust_c_id;
data.data = &cust;
data.ulen = sizeof(CUSTOMER);
data.flags = DB_DBT_USERMEM;
dbp->get(dbp, NULL, &key, &data, 0);
print_error(ret);
printf(”c_id = %d name = %s address = %s age = %d”,
cust.c_id, cust.name, cust.address, cust.age);
if(dbp != NULL)
dbp->close(dbp, 0);
return 0;
}
运行.test.out:
ERROR: DB_KEYEXIST: Key/data pair already exists
The number = 15
ERROR: DB_KEYEXIST: Key/data pair already exists
ERROR: DB_KEYEXIST: Key/data pair already exists
c_id = 1 name = javer address = chengdu age = 32
说明安装成功:以后研究:
然后安装libevent:
cd libevent:
[root@localhost]#cd libevent-1.2[root@localhost]#./configure --prefix=/opt/libevent && make && make install
安装成功后,安装crawl
参数为:
./configure --prefix=/opt/crall --with-libevent=/usr/checking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking target system type... i686-pc-linux-gnuchecking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking whether make sets ${MAKE}... yeschecking for working aclocal-1.4... missingchecking for working autoconf... missingchecking for working automake-1.4... missingchecking for working autoheader... missingchecking for working makeinfo... missingchecking for gcc... gccchecking for C compiler default output... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables... checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ANSI C... none neededchecking for a BSD-compatible install... /usr/bin/install -cchecking if we may use "-I/usr/include"... nochecking for libevent... /usr/configure: error: event.h or libevent.a not found in /usr/
而且已经把libevent-1.4.so.2 copy到/usr/lib
为什么不可以呢?