前言:
openfst的介绍就不必了,大家自行百度,下面进入正题。
Openfst下载:
目前kaldi版本为5.5,使用的openfst的版本为openfst-1.6.7.tar.gz,进入openfst官网,找到对应的tar.gz下载,如下图
Openfst的交叉编译:
1. 拷贝openfst-1.6.7.tar.gz至kaldi源码路径下的tools/
2. 执行解压命令 tar -zxvf openfst-1.6.7.tar.gz
3. cd openfst-1.6.7/
4. 执行命令 CXX=mips-linux-gnu-g++ CXXFLAGS=-mxgot ./configure --prefix=`pwd` --enable-static --enable-shared --enable-ngram-fsts --host=mips-linux-gnu LIBS="-ldl"
5. make
6. 修改/src/script/Makefile,在CXXFLAGS变量中添加 -G0 ,(注:在写此博客时,第5步编译完成后,已经能够顺利编译成功,则跳过该步。 之前这样修改可能是由于交叉工具链的版本不同,具体编译错误的日志没有保存,如果第5步编译失败,可以再尝试这一步后重新编译)
7. make install
8. 创建软链接: ln -s openfst-1.6.7 openfst
-------------------------------------------------------------------------------------------------------------------------------------------------------------
关于以上命令解释:
- --prefix 执行make install时lib库的安装位置为当前位置
- --enable-static 生成静态库 (实际在开发板中,使用的是静态库,当然也可以用动态库)
- --enable-shared 生成动态库
- --enable-ngram-fsts ngram是语言模型相关的,可以查阅ngram相关的资料
- CXXFLAGS=-mxgot 由于编译错误,具体见下面的报错
编译错误一:
报错log: relocation truncated to fit: R_MIPS_CALL16 against `std::allocator<char>::allocator()@@GLIBCXX_3.4', 详细log如下:
.libs/determinize.o: In function `fst::script::Determinize(fst::script::FstClass const&, fst::script::MutableFstClass*, fst::script::DeterminizeOptions const&)':
determinize.cc:(.text+0x43c): relocation truncated to fit: R_MIPS_CALL16 against `std::allocator<char>::allocator()@@GLIBCXX_3.4'
determinize.cc:(.text+0x46c): relocation truncated to fit: R_MIPS_CALL16 against `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@@GLIBCXX_3.4.21'
determinize.cc:(.text+0x4d0): relocation truncated to fit: R_MIPS_CALL16 against `std::allocator<char>::allocator()@@GLIBCXX_3.4'
determinize.cc:(.text+0x500): relocation truncated to fit: R_MIPS_CALL16 against `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@@GLIBCXX_3.4.21'
determinize.cc:(.text+0x56c): relocation truncated to fit: R_MIPS_CALL16 against `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()@@GLIBCXX_3.4.21'
determinize.cc:(.text+0x5b4): relocation truncated to fit: R_MIPS_CALL16 against `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()@@GLIBCXX_3.4.21'
determinize.cc:(.text+0x614): relocation truncated to fit: R_MIPS_CALL16 against `fst::script::MutableFstClass::SetProperties(unsigned long long, unsigned long long)'
determinize.cc:(.text+0x664): relocation truncated to fit: R_MIPS_CALL16 against `std::allocator<char>::allocator()@@GLIBCXX_3.4'
determinize.cc:(.text+0x690): relocation truncated to fit: R_MIPS_CALL16 against `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@@GLIBCXX_3.4.21'
determinize.cc:(.text+0x6f0): relocation truncated to fit: R_MIPS_CALL16 against `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()@@GLIBCXX_3.4.21'
.libs/determinize.o: In function `__static_initialization_and_destruction_0(int, int)':
determinize.cc:(.text+0x7c0): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Makefile:445: recipe for target 'libfstscript.la' failed
make[3]: *** [libfstscript.la] Error 1
解决方法:第4步中在变量CXXFLAGS中添加 -mxgot ,即 CXXFLAGS=-mxgot
如果有编译问题,欢迎留言,一起研究解决方法。