Installing Algorithm::SVMLight on Linux (Ubuntu)

Powered by Drupal, an open source content management system

Recently I attempted to install the Algorithm::SVMLight perl module via CPAN onto my Ubuntu box. It did not go well. I discovered that the CPAN package doesn’t include half of what you need, and I could not find any directions anywhere about how to get it to work. That compounded with svm-light’s lack of commenting made for a fun evening.

I’m posting my experience and solution here so maybe someone else who has the same problem can use it and not have to pull their hair out like I did.

First off.. forget about installing via CPAN. We're doing this manually. Here's what I had to do:

1. Download Algorithm::SVMLight to its own directory:

  1. cd ~
  2. wget Algorithm-SVMLight-0.08.tar.gz
  3. tar xzf Algorithm-SVMLight-0.08.tar.gz

2. Download svmlight into that directory:
  1. cd Algorithm-SVMLight-0.08
  2. mkdir svm_light
  3. cd svm_light
  4. wget svm_light.tar.gz
  5. tar xzf svm_light.tar.gz

3. Algorithm-SVMLight-0.08 includes a patch file SVMLight.patch that you need to apply:
  1. patch -p0 svmlight.patch

4. Now we need to build and install svmlight, and then create a shared library that Algorithm::SVMLight links into:
  1. cd svm_light

4.1. Open Makefile in an editor (eg. nano, pico, vi, gedit, whatever) and replace "CFLAGS= -O3" with "CFLAGS= -O3 -fPIC"

  1. make
  2. gcc -shared -o libsvmlight.so svm_common.o svm_learn.o svm_hideo.o svm_learn_main.o

5. Put this library somewhere Algorithm::SVMLight can find it (you need to be root to do this):
  1. su
  2. cp libsvmlight.so /usr/lib/
  3. exit
- or -
  1. sudo cp libsvmlight.so /usr/lib/

6. Before we can build Algorithm::SVMLight, we need to add a couple header files:
  1. cp *.h ../lib/Algorithm/

7. Now Algorithm::SVMLight should build and install:
(Note: on Debian I needed to apt-get libmodule-build-perl first.)
  1. cd ..
  2. perl Makefile.PL    # CPAN might download some stuff here. It's cool though.
  3. perl Build.PL
  4. make
  5. sudo make install

I think I've remembered everything correctly. With any amount of luck this should work. If not, send me an email and I'll try to help you out.

Tags