compiling libvirt and ruby-libvirt on mac os x

January 7, 2010

in mac, software

After a fair amount of battling with macports and compiling stuff from source code, I finally got libvirt to compile on my mac (running OS X 10.6.2), as well as successfully got the ruby-libvirt gem to install correctly. NB: this is only going to be a “client” install of libvirt — useful only for connecting to remote machines running libvirtd. That’s the only thing I want libvirt on my mac for anyways: managing remote machines with, say, the virsh command line client, or the ruby libvirt library.

You’ll need some prereqs. You may have already grabbed some or all from macports / fink, but I had trouble with those versions and decided to compile all of the required libs (that don’t come with OS X) from source. I like the “latest and greatest”, so as of this posting, these are the latest copies of the following libraries. Note that when installing these custom-compiled libraries, I’m going to always use the default prefix of /usr/local, as is recommended (see http://hivelogic.com/articles/using_usr_local). Let’s get started (by the way, if you don’t want to do this all manually, I’ve included a shell script and patch file at the bottom of this post):

Get the following and put it into a folder (i’m going to use ~/src):

  1. libgpgerror, 1.7: ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.7.tar.gz
  2. libgcrypt, 1.4.5: ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.4.5.tar.gz
  3. gnutls, 2.8.5: ftp://ftp.gnu.org/pub/gnu/gnutls/gnutls-2.8.5.tar.bz2
  4. libvirt, 0.7.5: ftp://libvirt.org/libvirt/libvirt-0.7.5.tar.gz

Compile libgpgerror:

tar -xzvf libgpg-error-1.7.tar.gz
cd libgpg-error-1.7
make
sudo make install

Compile libgcrypt:

tar -xzvf libgcrypt-1.4.5.tar.gz
cd libgcrypt-1.4.5
./configure --disable-asm
make
sudo make install

Compile gnutls:

tar -xzvf gnutls-2.8.5.tar.bz2
cd gnutls-2.8.5
./configure
make
sudo make install

And finally, compile libvirt. first extract:

tar -xzvf libvirt-0.7.5.tar.gz
cd libvirt-0.7.5

Then we have to alter some files. In src/util/network.c, change line 50:

50
        (*tab)[i] = ntohs(addr->inet6.sin6_addr.s6_addr16[i]);

to:

50
       (*tab)[i] = ntohs(addr->inet6.sin6_addr.s6_addr[i]);

In src/remote/remote_protocol.c, add this after line 9 (just after the #include lines):

10
11
#define xdr_uint32_t xdr_u_int32_t
#define xdr_uint64_t xdr_u_int64_t

In src/tools/virsch.c, change line 7050:

7050
    if (command_ret != WEXITSTATUS (0)) {

to:

7050
    if (command_ret != 0) {

Finally, in src/remote/rpcgen_fix.pl, change line 32:

32
    s/xdr_u_quad_t/xdr_uint64_t/g;

to:

32
    s/xdr_u_quad_t/xdr_u_int64_t/g;

and complete the compilation:

./configure --without-xen --without-sasl --without-avahi --without-polkit  --without-qemu --without-lxc --without-openvz --without-libvirtd --without-uml --without-vbox
make
sudo make install

And you’ve got libvirt!

Now, if you’d like the ruby-libvirt library, just do the following:

Download the gem from: http://libvirt.org/ruby/download/ruby-libvirt-0.1.0.gem, and run this in the directory the gem is located in:

sudo PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" gem install ruby-libvirt-0.1.0.gem

And done! Hopefully that wasn’t too painful. Figuring it out was…

The link below is to an archive containing a shell script and patch file to do the above work automatically (including downloading and extracting sources, and installing — because of that you will be prompted for your sudo password as it runs). You can also have the script do the gem installation by uncommenting the last two lines. Just download, put both files in a single directory, “chmod +x install_libvirt_osx.sh”, then “./install_libvirt_osx.sh”.

libvirt-os-x.zip

Cheers!

{ 3 comments… read them below or add one }

Charles January 22, 2010 at 4:03 am

Greate work!

matt January 22, 2010 at 10:38 am

thanks, charles!

peter January 28, 2010 at 4:35 am

I think I love you.

Leave a Comment

Previous post:

Next post: