Friday, January 29, 2016

How to Compile Fuego 1.1 on Ubuntu 14.04 LTS x64

My dad loves the game of GO, so I decided to let him play it vs AI. I first installed GNU GO on his computer and let him play against it; after a couple of times he played, he complained that GNU GO cannot even count accurately. So I figured I should provide him a better GO AI. That is how I decided to go for Fuego.

To install Fuego, download its source files
$ wget http://downloads.sourceforge.net/project/fuego/fuego/1.1/fuego-1.1.tar.gz

Unzip the source files
$ tar xfc fuego-1.1.tar.gz && cd fuego-1.1

Before configure, we need to install Boost library and build-essential
$ sudo apt-get install libboost-all-dev build-essential -y

Now, let's configure
$ ./configure

You will probably see some error saying 
configure: error: Could not find a version of the library!

The reason is that it cannot find the boost library, so we try to configure with the option
$ ./configure --with-boost-libdir=/usr/lib/x86_64-linux-gnu

The configure should have completed successfully. Let's compile.
$ make

You will probably encounter compilation error saying
GtpEngine.cpp:352:33: error: expected unqualified-id before numeric constant
         xtime_get(&time, boost::TIME_UTC);


We can fix this by replacing all instances of TIME_UTC with TIME_UTC_. Let's fix one by one first. Open the file
$ vim gtpengine/GtpEngine.cpp

Go to line 352 by entering :352 in vim and replace TIME_UTC with TIME_UTC_. Save and exit.

Let's compile again
$ make

This time you will see some error saying
SgPointSetUtil.h:67:25: error: reference 'm_pointSet' cannot be declared 'mutable' [-fpermissive]
     mutable SgPointSet& m_pointSet; // allow temp objects to modify


Let's solve this by removing 'mutable' in the file.
$ vim smartgame/SgPointSetUtil.h

After removing the keyword in line 67, save, and exit and give it another try.
$ make

You will encounter another error
GoGtpEngine.cpp:381:46: error: 'class boost::filesystem::path' has no member named 'native_file_string'
                            << m_sentinelFile.native_file_string() << "'";


This one is easy. If you search for native_file_string() method for Boost in Google, you will see that this method has been deprecated and replaced by string(). So, let's do that.
$ vim go/GoGtpEngine.cpp

In fact, you will have probably encountered another TIME_UTC error, which you can fix now, right? It is in the same file, so it should be easy.

Let's continue.
$ make

You will encounter another error saying
FuegoMain.cpp:65:55: error: invalid conversion from 'bool (*)(const string&) {aka bool (*)(const std::basic_string<char>&)}' to 'boost::enable_if_c<true, void>::type* {aka void*}' [-fpermissive]
     return path(programPath, boost::filesystem::native).branch_path();


This is again due to boost deprecation. One of the easiest ways to fix it for the moment is to replace line 65 with
return boost::filesystem::current_path();

This is not a remedy because this will only work if the executable is called from the same directory. However, let's just focus on compiling at the moment.

By the way, we will also need to include the boost::filesystem header file for the above quick fix to work. Insert the following at, say, line 11 of the FuegoMain.cpp file.
#include <boost/filesystem.hpp>

Let's continue.
$ make

We will encounter another complaint for native_file_string error, so let's fix it and compile again.
$ make

Lastly, we see another error saying
/usr/bin/ld: ../smartgame/libfuego_smartgame.a(libfuego_smartgame_a-SgUctSearch.o): undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line


As the error suggests, it is complaining because pthread library is missing. The easiest way to fix this is to run the g++ command with -lpthread option
$ cd fuegomain
$ g++ -g -O2 -DNDEBUG -Wall -Wextra -L/usr/lib/x86_64-linux-gnu  -o fuego fuego-FuegoMain.o fuego-FuegoMainEngine.o fuego-FuegoMainUtil.o ../gouct/libfuego_gouct.a ../go/libfuego_go.a ../smartgame/libfuego_smartgame.a ../gtpengine/libfuego_gtpengine.a -lboost_program_options -lboost_filesystem -lboost_system -lboost_thread -lpthread
$ cd ..

Let's continue!
$ make

You will most likely successfully compiled it finally! By the way, in order to save some compilation time, you may want to add in -j 2 option for make command, telling it to use 2 cores.


*** EDIT ***
After I created the post, I realized that Fuego website actually has a nice tutorial on building from the source files for Mac OS X and Linux. Furthermore, the latest Fuego source files can only be obtained via svn; these source files fix all of the problems mentioned above, except for the last one. In any case, I have created a script file that will build Fuego from the latest source files and install gogui and openjdk as well. Copy the script below and paste into a new file, say build_fuego_on_Ubuntu_14.04_x64.sh

#!/bin/bash
# this script attempts to compile and install fuego on Ubuntu 14.04 LTS x64


apt-get install -y subversion build-essential autoconf openjdk-7-jdk libboost-all-dev


sudo -u $SUDO_USER bash -c "svn checkout svn://svn.code.sf.net/p/fuego/code/trunk fuego"

cd fuego

#sudo -u $SUDO_USER bash -c "export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/"

sudo -u $SUDO_USER bash -c "autoreconf --force --install"
sudo -u $SUDO_USER bash -c "./configure --with-boost=/usr/lib/x86_64-linux-gnu/ --with-boost-libdir=/usr/lib/x86_64-linux-gnu/"
sudo -u $SUDO_USER bash -c "make -j 2"

cd fuegomain
sudo -u $SUDO_USER bash -c "g++  -g -O2 -DNDEBUG -Wall -Wextra -L/usr/lib/x86_64-linux-gnu/  -o fuego fuego-FuegoMain.o fuego-FuegoMainEngine.o fuego-FuegoMainUtil.o ../gouct/libfuego_gouct.a ../go/libfuego_go.a ../features/libfuego_features.a ../smartgame/libfuego_smartgame.a ../gtpengine/libfuego_gtpengine.a -lboost_program_options -lboost_filesystem -lboost_system -lboost_thread -lpthread"

cd ..
sudo -u $SUDO_USER bash -c "make -j 2"
cd ..
sudo -u $SUDO_USER bash -c "wget http://downloads.sourceforge.net/project/gogui/gogui/1.4.9/gogui-1.4.9.zip"
sudo -u $SUDO_USER bash -c "unzip gogui-1.4.9.zip"
cd gogui-1.4.9/lib

sudo -u $SUDO_USER bash -c "java -jar gogui.jar"


To run this file, simply set the execution flag and execute with sudo
$ chmod u+x build_fuego_on_Ubuntu_14.04_x64.sh
$ sudo ./build_fuego_on_Ubuntu_14.04_x64.sh
 
That's it!

5 comments:

  1. Thank you veeeery much! I just wanted to install Benzene for a Hex-AI which is dependent on fuego. It is kind of sad, that fuego is in such a bad shape regarding compilation/installation!

    ReplyDelete