在CentOS 7 Linux上安裝graph-tool. Building and Installing graph-tool on CentOS 7

在CentOS 7 Linux上安裝graph-tool. Building and Installing graph-tool on CentOS 7

最近因為使用需求而要在CentOS 7上頭安裝graph-tool,這是graph-tool官網對環境以及套件需求,只有倒數3項是不必要的: (I have to use graph-tool in CentOS 7, the following are the requirements for system environmentsand software packages. Only the last three are not necessary.)

Graph-tool was tested extensively only on GNU/Linux and MacOS X systems, but should also be usable on other systems where the below requirements are met.

  • A C++14 compiler (GCC version 5 or above, or clang version 3.4 or above).
  • The Boost libraries, version 1.54 or above.
  • Python version 2.7, 3 or above.
  • The expat library.
  • The SciPy python module.
  • The Numpy python module, version 1.7 or above.
  • The CGAL C++ geometry library, version 3.5 or above.
  • The sparsehash template library (optional, but recommended).
  • The GTK+ 3, cairomm, pycairo and matplotlib libraries, used for graph drawing (optional).
  • The Graphviz packaged for graph drawing, with the python bindings enabled (optional, deprecated).

但是CentOS7的gcc版本是gcc-4.8.5-4.el7.x86_64,比要求的gcc 5還舊,另外內建的boost是boost-1.53.0-25.el7.x86_64,比要求的1.54還舊;在安裝過程又遇到一堆dependency的問題,已經很久沒裝套件搞得這麼痛苦了,最後終於搞定,在此記錄一下:(However, the default gcc of CentOS7 is gcc-4.8.5-4.el7.x86_64 which is older than the required gcc 5. The built-in boost version is boost-1.53.0-25.el7.x86_64, which is older than boost 1.54. Besides, there are lot of dependency problems… This is a very hard way to setup all these tools for graph-tool. The following are the records to build and install graph-tool in CentOS 7 Linux.)

 

先裝devtoolset-4 (包新版gcc),官網說明: (First we have to install devtoolset-4 whcih includes newer gcc, and this is the instructions from the offical site of devtoolset)

# 1. Install a package with repository for your system:
# On CentOS, install package centos-release-scl available in CentOS repository:
$ sudo yum install centos-release-scl

# On RHEL, enable RHSCL repository for you system:
$ sudo yum-config-manager –enable rhel-server-rhscl-7-rpms

# 2. Install the collection:
$ sudo yum install devtoolset-4

 

Devtoolset是安裝在/opt/底下;我所安裝的graph-tool版本是graph-tool-2.17,會遇到幾個環境變數的設定,因為我是使用tcsh,因此: (The version of graph-tool is graph-tool-2.17. Since Devtoolset is installed in /opt/, and I use tcsh as my shell that I have to change some environment variables as follows. If your shell is bach, just export the following variables )
setenv CC “/opt/rh/devtoolset-4/root/usr/bin/gcc”
setenv CPP “/opt/rh/devtoolset-4/root/usr/bin/cpp”
setenv CXX “/opt/rh/devtoolset-4/root/usr/bin/c++”
setenv LIBS “/opt/rh/devtoolset-4/root/usr/lib/gcc/x86_64-redhat-linux/5.2.1/libstdc++_nonshared.a”

 

原本CentOS 7上頭的CGAL版本也不合,接著下載並安裝CGAL-4.8.1 (The default CGAL in CentOS is not fitted and have to install CGAL-4.8.1. Just download newer CGAL and install it)
# cd CGAL-4.8.1
# cmake -DCMAKE_CXX_COMPILER:FILEPATH=/opt/rh/devtoolset-4/root/usr/bin/c++
# make
# make install

 

重裝graph-tool,./configure又遇問題 (Go back to install graph-tool, some problems occur when ./configure)
No package cairomm-1.0 available.
–>
# yum install cairomm-devel

 

再次./configure,接著又有新問題  (./configure graph-tool again, another problem)
configure: error: pycairo headers not found
–>
# yum install pycairo-devel

 

再./configure又發生新問題: (./configure again, oops)
configure: error: sparsehash headers not found
–>
# yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/s/sparsehash-devel-1.12-3.el7.x86_64.rpm
//無法解決, However, not solved

直接用pip install sparsehash
# pip install sparsehash

 

又缺cython (no cython installed)
–>
# pip install cython

–>
# pip install sparsehash

 

graph-tool重新 ./configure (./configure graph-tool again)
configure: error: sparsehash headers not found

放棄,繞一圈,改這邊的做法,裝epel的repo (Give up XD, use the following two suggestions by googleing)
https://lists.skewed.de/pipermail/graph-tool/2015-October/002157.html

http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/

–>

## RHEL/CentOS 7 64-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-7.noarch.rpm
# rpm -ivh epel-release-7-7.noarch.rpm

 

搞了好久,參考這篇. Just use the following argument by ./configure –with-sparsehash-prefix=google
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/Building-graph-tool-on-CentOS-7-td4025761.html   <– 非常詳細. Follow this page
# ./configure –with-sparsehash-prefix=google

./configure終於pass了,但make又出error  (finally pass ./configure, but brings new problem when make)
graph_all_circuits.cc:18:43: fatal error: boost/graph/hawick_circuits.hpp: No such file or directory
compilation terminated.
make[4]: *** [graph_all_circuits.lo] Error 1

–>靠腰,竟然是原始檔裡缺了一個.hpp,只好回過頭來重載boost,並將hawick_circuits.hpp複製到graph-tool的目錄下 (hawick_circuits.hpp is not found in the source code of boost directory in graph-tool, thus I down the boost and copy hawick_circuits.hpp to graph-tool)
http://netix.dl.sourceforge.net/project/boost/boost/1.61.0/boost_1_61_0.tar.gz
# cp hawick_circuits.hpp graph-tool-2.17/src/boost-workaround/boost/graph

 

再次make,再次遇問題 (make again, new problem again)
raph_subgraph_isomorphism.cc:241:25:   required from here
graph_subgraph_isomorphism.cc:171:34: error: ‘vf2_subgraph_mono’ was not declared in this scope
make[4]: *** [graph_subgraph_isomorphism.lo] Error 1
make[4]: Leaving directory `/tmp/graph-tool-2.17/src/graph/topology’
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/tmp/graph-tool-2.17/src/graph’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/tmp/graph-tool-2.17/src’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/graph-tool-2.17′
make: *** [all] Error 2

看來缺了不少lib,再次參考這篇,但這篇有錯,會無法pass,這是for CentOS 6的repo… (Many libs are lacked. Read he following instruction but its for CentOS6 but not suitable for CentOS 7)
http://stackoverflow.com/questions/33050113/how-to-install-boost-devel-1-59-in-centos7

結果繼續發生error (error since error version)
Error: Package: libboost_log1_59_0-1.59.0-1.x86_64 (enetres)
           Requires: libicuuc.so.42()(64bit)

–>不行,這是CentOS 6的 (This is not for CentOS 7 that I have to remove the /etc/yum.repos.d/enetres.repo )
移除/etc/yum.repos.d/enetres.repo 重來

 

走投無路了,最後參考以下兩篇,直接裝boost_1_61_0  (Finally, I read the following two pages and just install boost_1_61_0 )
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/Building-graph-tool-on-CentOS-7-td4025761.html
以及
http://unix.stackexchange.com/questions/98918/how-to-install-a-custom-boost-version-in-centos

# mv boost_1_61_0/ /usr/local/
# sudo ln -s /usr/local/boost_1_61_0/ /usr/local/boost

# cd boost_1_61_0
# ./bootstrap.sh –prefix=/usr/local
# ./b2 install –with=all

//ok,  boost is installed

 

重設環境變數 (reset environment again)
setenv CC “/opt/rh/devtoolset-4/root/usr/bin/gcc”
setenv CPP “/opt/rh/devtoolset-4/root/usr/bin/cpp”
setenv CXX “/opt/rh/devtoolset-4/root/usr/bin/c++”
setenv LIBS “/opt/rh/devtoolset-4/root/usr/lib/gcc/x86_64-redhat-linux/5.2.1/libstdc++_nonshared.a”
setenv LD_LIBRARY_PATH “/usr/local/lib”

 

再次安裝graph-tool (reconfigure graph-tool)
# ./configure –with-sparsehash-prefix=google –with-boost=/usr/local/boost –with-boost-libdir=/usr/local/boost/libs CPPFLAGS=”-I/usr/local/boost” LDFLAGS=”-L/usr/local/boost/libs”
過了!pass!!!

重新make (make and install again)
# make
# make check
# make install
安裝成功! (Yeah!!!)

 

如果是用tcsh或csh,則在.tcshrc或.cshrc 加入((Remember to add  the following environment variable in your .tcshrc or .cshrc if you use tcsh or csh)
setenv LD_LIBRARY_PATH “/usr/local/lib”

若使用bach,記得在.bashrc加入 (If you use bash, just add the following in your .bashrc)
export LD_LIBRARY_PATH=/usr/local/lib

 

python裡若如果沒任何error則完成 (To see if graph-tool was set up successfully, just check by)
# python
>>> import graph_tool

if no ImportErr occurs, graph-tool was installed successfully.

Leave a Reply