2012年12月27日星期四

import cdec into eclipse

Building Cdec:

(http://www.cdec-decoder.org/guide/compiling.html)
1) Download cdec

git clone git://github.com/redpony/cdec.git


2) Install third-party software, including:
autoconf/automake
libtool
boost
python

3) Compiling cdec

cd cdec
autoreconf -ifv
./configure [--with-boost=/path/to/boost-install]
make
./tests/run-system-tests.pl

Error running make:

fast_align.cc:216:   instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/hashtable:863: error: ‘Internal::hash_code_base::m_h1’ has incomplete type

Solution:
word-aligner/fast_align.cc: line 216:

unordered_map,unsigned>::iterator it = size_counts.begin();   ==>
unordered_map,unsigned,boost::hash > >::iterator it = size_counts.begin();

4) ....

Importing cdec project into eclipse
1) Create a C++ project cdec_eclipse
2) Copy folders decoder/, utils/, and kenlm/ into cdec_eclipse, and config.h
3) Compiling cdec_eclipse will get such errors of "...h" not found
    3.1) Modify source files as to include .h files appropriately.
    3.2) In terms  of error KENLM_MAX_ORDER in klm/lm/left.hh not defined,
            Properties --> C/C++ Build --> Settings --> Cross GCC Compiler (Cross G++ Compiler) --> Symbols --> Define symbols (-D), add KENLM_MAX_ORDER=6.
    3.3) Properties --> C/C++ Build --> Settings --> Cross GCC Compiler (Cross G++ Compiler) --> Includes --> Include Paths (-I), add /..../decoder, /.../mteval, /.../utils, /.../klm,
4) Exclude decoder/cfg_test.cc from build

5) Add #include "hg.h" in decoder/tromble_loss.h

6) Add -lz in Properties --> C/C++ Build --> Settings --> Cross G++ linker
    (-lz is always needed if zlib is included)
7) Add boost libraries in Properties --> C/C++ Build --> Settings --> Cross G++ linker --> Libraries
    boost libraries should be present in /usr/local/lib. The lib files are in format of libboost***.a (e.g., libboost_date_time.a). To link these libraries, add boost**** (e.g., boost_data_time, NOT the full name) in eclipse.
    Here I added boost_iostreams, boost_system boost_unit_test_framework, boost_context, boost_filesystem, boost_program_options.

8) For errors like 'duplicate symbol _main in:' modify related source files and comments main functions.

9) For errors like duplicate symbol init_unit_test_suite(int, char**), find related source files (mostly are in the format **_test.cc) and exclude them from building.

10) For errors like duplicate symbol InitCommandLine, find related source files and use another function name.

*Note* If boost is installed in somewhere else, add "/path/to/boost" (for example /home/.../boost_1_53_0/include) in Properties --> C/C++ Build --> Settings --> Cross GCC Compiler (Cross G++ Compiler) --> Includes --> Include Paths (-I), and add /path/to/boost/lib in Properties --> C/C++ Build --> Settings --> Cross G++ linker --> Library search path (-L)

When run or debug the programme, for errors like 'error while loading shared libraries: libboost_context.so.1.53.0': a solution is to set LD_LIBRARY_PATH to include the directory where the boost thread library is. in Run --> Debug Configurations... --> Environment --> New, and add LD_LIBRARY_PATH for name and /home/.../boost_1_53_0/lib:$LD_LIBRARY_PATH for value.


Debugging cdec in eclipse
1) For error "Program is not a recognized executable." which might be due to the wrong binary parsers used. Add the correct binary parser under Project --> Properties --> C/C++ Build --> Settings --> Binary Parsers to solves he problem. (Dunno which binary parsers are correct ones. Try one by one).