首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

clucene装配与使用(2)

2013-01-23 
clucene安装与使用(2)直接调用clucene核心源码src为mysql数据库建立索引,以clucene-0.9.21b为例。(/clucene

clucene安装与使用(2)

直接调用clucene核心源码src为mysql数据库建立索引,以clucene-0.9.21b为例。

(/clucene-core-0.9.21b/src/demo/中有示例,demo为最好的程序参考)

需要clucene核心源码CLucene.h和CLucene文件夹,从网上download一个makefile模板(我使用的是实验室一个makefile模板),修改其中可配置部分即可:

## Customizable Section: adapt those variables to suit yourprogram.
##==========================================================================

# The pre-processor and compileroptions.
MY_CFLAGS= -m32 -O3 -DOS_LINUX    #ICTCLAS分词的其他配置填在这里

# The linker options.
MY_LIBS   =-L/CLucene -L/usr/lib/mysql ./ICTCLAS/libICTCLAS50.so//L说明lab是个目录,./直接指定

# The pre-processor options used by the cpp (man cpp formore).
CPPFLAGS  = -c -I/usr/include -I ./ -I ./CLucene -I ./CLucene/analysis -I./CLucene/analysis/standard -I ./CLucene/config -I ./CLucene/debug-I ./CLucene/document -I ./CLucene/index -I ./CLucene/queryParser-I ./CLucene/search -I ./CLucene/store -I./CLucene/util

# The options used in linking as well as inany direct use of ld.
LDFLAGS   = -lpthread-lmysqlclient  #安装版的库文件,会自动去usrl/lib里面找,不要会出现unreference错误

# The directories in which source files reside.
# If not specified, only the current directory will beserached.
SRCDIRS   = ./\
           ./CLucene  \
   ./CLucene/analysis \
   ./CLucene/analysis/standard\
   ./CLucene/config\
   ./CLucene/debug\
   ./CLucene/document\
   ./CLucene/index\
   ./CLucene/queryParser\
   ./CLucene/search\
   ./CLucene/store\
   ./CLucene/util

# The executable file name.
# If not specified, current directory name or `a.out' will beused.
PROGRAM   = main

注意:一定要添加mysql编译所需lib文件:-L/usr/lib/mysql 和-lmysqlclient,否则会能包含<mysql/mysql.h>头文件,但是链接不上mysql的接口函数。

可能出现的问题:

1.数据库接口函数unreferenced,向makefile中添加-L/usr/lib/mysql 和-lmysqlclient应该就能解决

2..d文件错误,很大可能是编译单个cpp文件时,文件中头文件路径有问题,链接不上。修改路径后,删除相应.d文件再make

3. 分词一直添加不上去,总是error:collect2 ld XXXX, 最后试出来要添加-lICTCLAS50链接库


下面是关于中科院分词ICTCLAS50使用的部分注意事项:

makefile需要的配置如下:

main: main.cpp text_pro.cpp ICTCLAS50.h

g++ -g main.cpp text_pro.cpp ./libICTCLAS50.so -lICTCLAS50 -m32 -O3 -DOS_LINUX -o main

-lICTCLAS50一般可以不要,但有时(例如上面情况)必须添加。

有时候makefile无错误了 但是编译还是有问题,此时可试着把

libICTCLAS50.so拷贝到usr/local/lib

libICTCLAS50.a拷贝到usr/local/lib

然后再vim /etc/ld.so.conf: 添加一行/usr/local/lib,然后再ldconfig


热点排行