SRILM 的编译
取自 自然语言处理百科
(1)
使用系统是ubuntu 7.10。
在sri网站上,可以找到这个软件依赖的包。
http://www.speech.sri.com/projects/srilm/download.html
Prerequisites
Besides the SRILM distribution, you will also need the following freely available tools:
* A template-capable ANSI-C/C++ compiler, preferably gcc version 3.4.3 or higher. * GNU make, to control compilation and installation. * GNU gawk, required for many of the utility scripts. * GNU gzip to unpack the distribution, and to allow SRILM programs to handle ".Z" and ".gz" compressed datafiles (highly recommended). * bzip2 to handle ".bz2" compressed files (optional). * p7zip to handle "7-zip" compressed files (optional). * The Tcl embeddable scripting language library (only required for some of the test executables). * The CYGWIN porting layer, to build SRILM on a Microsoft Windows system. CYGWIN comes with the packages above, so this is all you will need.
这里边大多是废话,可能如果安装fedora的话,这些包已经都已安装。但ubuntu里没有。
这里需要apt-get一下g++和tcl。由于在linux下,因此cygwin就不用了。
另外可能需要安装的东西:csh,gawk。好像默认的ubuntu中也没有。
这里注意,tcl最好装tcl8.x和tcl8.x-dev两个包.
(2)
阅读文章,下面链接http://weiqk.spaces.live.com/Blog/cns!2115755AE5F9E79!221.entry
这个文章里详细讲述了怎样修改makefile和i686文件。但是我按照其中方法修改后,效果并不好,编译会有错误。
但是很重要的一点就是,这个文章指出了,应该修改哪几个地方。
(3)修改
在有了以上准备后,开始修改。首先修改Makefile:
前两行:
SRILM = $(PWD)
MACHINE_TYPE := $(shell $(SRILM)/sbin/machine-type)
ok,就这些。
然后修改/common/Makefile.machine.i686
修改编译器
- Use the GNU C compiler.
GCC_FLAGS = -mtune=pentium3 -Wreturn-type -Wimplicit CC = gcc $(GCC_FLAGS) CXX = g++ $(GCC_FLAGS) -DINSTANTIATE_TEMPLATES
cc,和cxx行,也可以写全路径,没有影响。
这里要注意一个地方:有的机器是amd64位机器,这时需要将gcc_flag改为:
GCC_FLAGS = -march=athlon64 -m64 -Wreturn-type -Wimplicit
修改Tcl,安装后的地址在/usr/lib/tcl8.4。
这里曾经百思不解,事实证明,按照上面那片文章中的修改方法不能正确编译。而必须要用这几行。
# Tcl support (standard in Linux) TCL_INCLUDE = -I /usr/include/tcl8.4 TCL_LIBRARY = -L /usr/lib/tcl8.4
ok,其他的也不需要改了。
修改环境变量,添加/usr/include/tcl8.4和 /usr/lib/tcl8.4
(4)编译:
回到目录下,
make World
等待。。。
这里会遇到问题,有一次,提醒找不到tcl.h出现这种情况时,把 /usr/include/tcl8.4下的几个h文件拷贝到srilm/misc/src文件夹下,与tclmain.cc文件放在一起
成功。
(5)检测
按照文章介绍方法
首先:
export PATH="$PATH:/home/yudong/srilm/bin/i686:/home/yudong/srilm/bin"
然后:
cd test
make all
等待。。。
(6)修改环境变量
cd /etc
vim profile
这个文件的修改,曾经摸不着头脑,打开一看,啥都不懂
后来硬头皮添加一行。
if [ "$PS1" ]; then
if [ "$BASH" ]; then
PS1='\u@\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
export PATH="$PATH:/home/yudong/srilm/bin/i686:/home/yudong/srilm/bin"
umask 022
ok了,注销一下,或者重启一下,就可以用了。
转自:http://hi.baidu.com/wit_yd/blog/item/6b6681272c8ed206918f9dbe.html

