Camellia and Ruby on Mac OS X

Camellia is ‘an open source Image Processing & Computer Vision library’ that can do some interesting stuff directly from Ruby.

Unfortunately, the Ruby library for Camellia is only available as a RubyGem in two flavours, i386-mswin32 and i486-linux, neither of which is much use if you’re on Mac OS X.

Fortunately, with a bit of work, you can get it to compile. I’ll assume in these instructions that you’re using Ruby from MacPorts. I also can’t guarantee that this works on PowerPC Macs: I’ve only tried it on Intel.

The first prerequisite is the Camellia library itself; that’s a straightforward case of downloading the source (use the ‘Unix/Linux’ distribution), expanding the archive and doing the usual incantation:

./configure && make && sudo make install

For the gem itself, it’s a bit more complicated. There’s no source distribution as such, but it’s easy enough to pick apart the file once you’ve downloaded it (go for the i486-linux gem).

mkdir camellia-gem
cd camellia-gem
tar xvf ../camellia-2.5.10-i486-linux.gem
tar zxvf data.tar.gz
cd ext

The only thing that stops the gem compiling out of the box is a couple of linker settings; change the line in extconf.rb that reads

CONFIG['LDSHARED'] = "g++ -shared -lCamellia"


"g++ -lCamellia -bundle -flat_namespace -undefined suppress"

You can now build the extension:

ruby extconf.rb && make

You should now have a camellia.bundle file; check whether it has built correctly:

ruby -d -w -e 'require "camellia"'

If you get no errors, everything worked. You can copy camellia.bundle into your site_ruby directory so that it’s available to all programs:

sudo cp camellia.bundle /opt/local/lib/ruby/site_ruby/1.8/

That’s it! Now try some of the demo code ....


  1. Tieg

    Wrote at 2007-05-16 16:55 UTC using Firefox on Mac OS X:

    Nice! Thanks for the pointer; I’ll try this later with /usr/local/lib ruby. Anything that has “camellia” in its name has to be good.
  2. Peter Cooper

    Wrote at 2007-05-17 16:44 UTC using Firefox on Mac OS X:

    I’ve updated the Ruby Inside post with a link to this. Nice detective work :)
  3. Marc

    Wrote at 2008-06-09 07:48 UTC using Firefox on Mac OS X:

    $ make
    make: *** No rule to make target `ruby.h’, needed by `camellia_ruby_wrap.o’. Stop.

    any idea?

    $ ruby -rrbconfig -e ‘puts ::Config::CONFIG[“includedir”]’

    A ruby.h does exist in /usr/local/include
  4. Ezekiel

    Wrote at 2008-12-31 11:15 UTC using Firefox 3.0.5 on Mac OS X:

    I am having the same exact issue as Marc.
  5. Vishnu Gopal

    Wrote at 2009-05-23 23:05 UTC using Safari 528.17 on Mac OS X:

    For those facing problems, you have to tweak the Makefile in the ext directory as well. Change to:

    topdir = /opt/local/lib/ruby/1.8/i686-darwin9 (for leopard)

    Change all occurences of /usr/local to /opt/local if you are using Macports.

    You have to remove ”-Wl,-export-dynamic” from DLDFLAGS and ”-Wl,-R’$(libdir)’” from LIBPATH

    Also remove ”-lcrypt” from LIBS

    Then make, also cp camellia.bundle for everything to work right!
  6. Anton Djurasaj

    Wrote at 2009-06-24 23:18 UTC using Firefox 3.5 on Windows 7:

    Does anybody know how to install camellia as a gem on Ubuntu 9.04 (64-bit). The one from the gem repo won’t install—it says it can’t find it—probably because it’s 32-bit. I tried Vishnu’s trick above and I do get the file, but can’t get camellia.bundle to generate.

    I’d appreciate any help with this.
  7. Anton Djurasaj

    Wrote at 2009-06-24 23:53 UTC using Firefox 3.5 on Windows 7:

    I forgot to include my Makefile. Please note that “g++ -lCamellia -bundle -flat_namespace -undefined suppress” did not work as it complains about invalid switch ’-bundle’. Also, I have modified paths in accordance with my system (Ubuntu 9.04 64-bit).

    SHELL = /bin/sh

    #### Start of system configuration section. ####

    srcdir = .
    topdir = /usr/lib/ruby/1.8/x86_64-linux
    hdrdir = $(topdir)
    VPATH = $(srcdir):$(topdir):$(hdrdir)
    prefix = /usr
    exec_prefix = $(prefix)
    sitedir = $(prefix)/lib/site_ruby
    rubylibdir = $usr/lib/ruby/$(ruby_version)
    docdir = $(datarootdir)/doc/$(PACKAGE)
    dvidir = $(docdir)
    datarootdir = $(prefix)/share
    archdir = $(rubylibdir)/$(arch)
    sbindir = $(exec_prefix)/sbin
    psdir = $(docdir)
    localedir = $(datarootdir)/locale
    htmldir = $(docdir)
    datadir = $(datarootdir)
    includedir = $(prefix)/include
    infodir = $(datarootdir)/info
    sysconfdir = $(prefix)/etc
    mandir = $(datarootdir)/man
    libdir = $(exec_prefix)/lib
    sharedstatedir = $(prefix)/com
    oldincludedir = $(DESTDIR)/usr/include
    pdfdir = $(docdir)
    sitearchdir = $(sitelibdir)/$(sitearch)
    bindir = $(exec_prefix)/bin
    localstatedir = $(prefix)/var
    sitelibdir = $(sitedir)/$(ruby_version)
    libexecdir = $(exec_prefix)/libexec

    CC = gcc
    LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
    LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -L.

    CFLAGS = -fPIC -g -O2
    INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
    DLDFLAGS = -rdynamic
    LDSHARED = g++ -shared -lCamellia
    AR = ar
    EXEEXT =

    RUBY_SO_NAME = ruby
    arch = x86_64-linux
    sitearch = x86_64-linux
    ruby_version = 1.8
    ruby = /usr/local/bin/ruby
    RUBY = $(ruby)
    RM = rm -f
    MAKEDIRS = mkdir -p
    INSTALL = /usr/bin/install -c
    INSTALL_PROG = $(INSTALL) -m 0755
    INSTALL_DATA = $(INSTALL) -m 644
    COPY = cp

    #### End of system configuration section. ####

    preload =

    libpath = $(libdir)
    LIBPATH = -L’$(libdir)’


    extout =
    extout_prefix =
    target_prefix =
    LIBS = -ldl -lm -lc
    SRCS = camellia_ruby_wrap.cxx
    OBJS = camellia_ruby_wrap.o
    TARGET = camellia
    DLLIB = $(TARGET).so

    RUBYCOMMONDIR = $(sitedir)$(target_prefix)
    RUBYLIBDIR = $(sitelibdir)$(target_prefix)
    RUBYARCHDIR = $(sitearchdir)$(target_prefix)

    CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
    CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak



    @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
    @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)

    install: install-so install-rb

    install-so: $(RUBYARCHDIR)
    install-so: $(RUBYARCHDIR)/$(DLLIB)
    install-rb: pre-install-rb install-rb-default
    install-rb-default: pre-install-rb-default
    pre-install-rb: Makefile
    pre-install-rb-default: Makefile
    $(MAKEDIRS) $@

    site-install: site-install-so site-install-rb
    site-install-so: install-so
    site-install-rb: install-rb

    .SUFFIXES: .c .m .cc .cxx .cpp .C .o





    $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<

    $(DLLIB): $(OBJS)
    -$(RM) $

    $(OBJS): ruby.h defines.h
  8. Liborio Cannici

    Wrote at 2009-10-07 08:39 UTC using Firefox 3.5.3 on Mac OS X:

    No luck on Snow Leopard!
    I have followed what Vishnu Gopal suggested on 23 May and I get lots of errors that ends with:

    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [] Error 1
  9. Mosselman

    Wrote at 2011-10-30 21:31 UTC using Safari 534.48.3 on Mac OS X:

    Thank you! It worked for me on Lion even.

    While we are on the subject. Any ideas on how to enable camellia to be useful inside of rails?
  10. Poweratom

    Wrote at 2013-12-29 20:44 UTC using Chrome 31.0.1650.63 on Mac OS X:

    And of course, for the lucky ones like me in 2013, we can now just run “brew install camellia” and call it a day. :)