Thursday, January 16, 2014

Compiling Grive on Centos with unsupported Boost/CMake version.

In the absence of a Google Drive client version for linux, I tried to compile grive (0.3.0-pre) which is an open source client using the Google APIs:

Install all dependencies first, try yum install gcc-c++ expat-devel json-c-devel libgcrypt-devel curl-devel

If the CMake version is old, get the appropriate version of CMake and do not install it:

#cd /usr/local/src
#wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2-Linux-i386.sh
#./cmake-2.8.10.2-Linux-i386.sh .
That's for i386, it seems for x64 you need to compile it from source. 

If the Boost version is older and cmake complains about it:

1. Download the appropriate version of boost (most current right now is 1.55) and extract it to /usr/local/src:

#tar -xvf boost_1_55_0.tar.bz2
#cd boost_1_55_0
#./bootstrap.sh --prefix=/usr/local/src/boost_1_55_0/lib/
#./b2  --build-dir=/usr/local/src/boost_1_55_0/lib/ --with-system --with-filesystem --with-program_options --with-test

2. Download and compile yajl. (./configure && make). Assuming that it's located at /usr/local/src/yajl

3. Back to the Grive directory. I should mention that I removed bgrive from CMakeLists.txt because I did not need it. You must add the following commands in CMakeLists.txt
INCLUDE_DIRECTORIES(/usr/local/src/boost_1_55_0)
INCLUDE_DIRECTORIES(/usr/local/src/yajl/build/yajl-2.0.5/include/)
link_directories(/usr/local/src/yajl/build/yajl-2.0.5/lib/)
link_directories(/usr/local/src/boost_1_55_0/stage/lib/)
Then run:
#../cmake-2.8.10.2-Linux-i386/bin/cmake -D BOOST_ROOT:FILEPATH="/usr/local/src/boost_1_55_0"  -D Boost_LIBRARY_DIRS:FILEPATH="/usr/local/src/boost_1_55_0/stage/lib" .
 (There is a dot as the very last argument).

Try to run make.

If you get any errors about ambiguous log entries, do the following:

Assuming you have vim, edit grive/src/main.cc and type as an editor command: %s/log::/gr::log::/

If you don't have vim what you need to do is to change all instances of log:: to gr::log::

Finally if you still get errors like "undefined reference to `gr::Json::Json(long const&)" make the trivial edits to libgrive/src/drive/State.cc as described here.

After thoughts:

To install to another binary compatible machine without rebuilding, you need to copy the compiled libraries and install the dependencies as well:  

Install depedencies: #yum install expat json-c libgcrypt curl

Copy all compiled libraries to /usr/local/lib[64]:

  1.  From /usr/local/src/boost_1_55_0/stage/lib/
    • All *.so.1.55.0
  2.  From /usr/local/src/yajl/build/yajl-2.0.5/lib/
    •  libyajl.so.2.0.5

Create symbolic links for all the libraries you've copies and use the library name without the appended version as the link name, eg:

#ln -s libboost_filesystem.so.1.55.0 libboost_filesystem.so

Copy the grive binary to /usr/local/bin or any convenient location

Finally run ldconfig /usr/local/lib[64]
Post a Comment