linux系统下CRF++及GCC安装

来源:互联网 发布:java移植安卓游戏破解 编辑:程序博客网 时间:2024/06/10 00:14

转载: http://blog.sina.com.cn/s/blog_8e1edee90101pp6x.html


CRF工具包下载地址及使用说明:https://taku910.github.io/crfpp/

折腾了好几天,但还未成功安装和应用,小抓狂,但做事情本不就是如此,总会走点弯路,但只要坚持,总会成功的,所以,一定要挺住,抓狂的时候放松放松,然后接着干!

    1、起初自己PC上装的Ubuntu13.10,工作过程中总是出现死机情况,至今不知原因在哪里,不知是系统的原因还是个人电脑的问题,后来重新安装Ubuntu12.04.4,情况较好,能够正常运行。

    2、安装CRF++:

    使用命令./configure,报错:

    configure: error: Your compiler is not powerful enough to compile CRF++. If it should be, see config.log for more information of why it failed.

    执行命令sudo apt-get install g++安装g++,继续

    cd /opt/CRF++-0.58

    sudo ./configure

    sudo make

    sudo make install

    安装成功!

    注意:ubuntu 默认安装时没有给root用户设置口令,也没有启用root帐户,如果想作为root用户来运行命令可以使用sudo命令达到此目的。

    但在运行时又出现问题:

    spring@spring-pc:~$ cd CRF++-0.58/example/basenp

    spring@spring-pc:~/CRF++-0.58/example/basenp$ crf_learn template train.data model

crf_learn: error while loading shared libraries: libcrfpp.so.0: cannot open shared object file: No such file or directory

    现正在调试。

    3、在刚开始安装CRF++过程中没有安装成功,也没有仔细阅读报错提醒,就自以为是没有安装gcc的原因,因为在网上看到装CRF++需要gcc3.0或以上版本的支持,所以就先折腾了几天gcc的安装,安装过程复杂(比想像中的复杂的多),报错不断,不过最终总算是成功了,也算是没有白费几天功夫。现总结如下:

    1)下载gcc-4.8.2.tar.gz

    2)将gcc-4.8.2.tar.gz放到/opt文件夹下并解压

    cd /opt

    tar zxfv gcc-4.8.2.tar.gz

    3)创建安装目录

    mkdir /usr/local/gcc-4.8.2

    4)进入安装目录

    cd /usr/local/gcc-4.8.2

    5)配置安装文件

    /opt/gcc-4.8.2/configure –prefix=/usr/local/gcc-4.8.2

    报错:

    configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.

    Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their locations.  Source code for these libraries can be found at their respective hosting sites as well as at ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also http://gcc.gnu.org/install/prerequisites.html for additional info.  If you obtained GMP, MPFR and/or MPC from a vendor distribution package, make sure that you have installed both the libraries and the header files.  They may be located in separate packages.

    错误说明要安装gcc需要GMP、MPFR、MPC这三个库,可从ftp://gcc.gnu.org/pub/gcc/infrastructure/下载相应的压缩包。由于MPFR依赖GMP,而MPC依赖GMP和MPFR,所以要先安装GMP,其次MPFR,最后才是MPC。这里三个库我用的版本分别是gmp4.3.2,mpfr2.4.2和mpc0.8.1,都放在 /opt文件夹下。

    a. 安装gmp-4.3.2

    tar jxvf gmp-4.3.2.tar.bz2

    mkdir /usr/local/gmp-4.3.2

    cd /usr/local/gmp-4.3.2

    /opt/gmp-4.3.2/configure –prefix=/usr/local/gmp-4.3.2

    又报错:缺少m4,m4是一个宏处理器。在系统自带的软件中心可以找到m4,直接点击“安装”即可成功安装。

    继续操作

    Make

    make install

    make install后出现提示,大概意思就是强烈建议执行“make check”,所以继续执行 make check,成功安装,结束。

    b. 安装mpfr-2.4.2

    tar jxvf mpfr-2.4.2.tar.bz2

    mkdir /usr/local/mpfr-2.4.2

    cd /usr/local/mpfr-2.4.2

    /opt/mpfr-2.4.2/configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2

    Make

    make check

    make install

    c. 安装mpc-0.8.1

    tar zxvf mpc-0.8.1.tar.gz

    mkdir /usr/local/mpc-0.8.1

    cd /usr/local/mpc-0.8.1

     /opt/mpc-0.8.1/configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2

    make

    make check

    make install

    至此,三个库文件都安装成功,再次配置GCC安装选项

    cd /usr/local/gcc-4.8.2

    /opt/gcc-4.8.2/configure --prefix=/usr/local/gcc-4.8.2 -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 –with-mpc=/usr/local/mpc-0.8.1

    6)编译安装文件

    Make

    看到网上说编译过程中又会报错,需要先添加环境变量LD_LIBRARY_PATH以指出前面三个库的位置,所以也就没有耗时尝试了,直接添加后再继续安装,键入以下命令:

    spring@spring-pc:/usr/local/gcc-4.8.2$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.1/lib:/usr/local/mpfr-2.4.2/lib

    不过过程中还是出现了错误:

    configure: error: C++ compiler missing or inoperational

    make[2]: *** [configure-stage1-libcpp] 错误 1

    make[2]:正在离开目录 `/usr/local/gcc-4.8.2'

    make[1]: *** [stage1-bubble] 错误 2

    make[1]:正在离开目录 `/usr/local/gcc-4.8.2'

    make: *** [all] 错误 2

    执行命令apt-get install g++安装g++

    (出现了这个错误以后我才发现其实不用这么麻烦的安装gcc后再安装CRF++,浪费了好长时间。所以当g++安装成功后,我先又尝试安装了CRF++,然后再继续安装gcc。)

很尴尬,至今问题还未解决,正在努力中。

    总结:出现报错应仔细阅读错误原因,对症下药,切忌不明原因随便放弃或盲目纠错,费时费力。(整个过程中最大的收获莫过于此)

    其实现在还是疑惑,linux下使用CRF++是否必需安装gcc,还是说有g++就够了,究其原因还是自己没有搞明白CRF++的原理,这也是要继续进行的工作。


0 0