Friday, March 22, 2013

Installing HTK on OS X

I already read a blog post about this (Thanks, Patrick O'Keefe!) but my experience was different enough that I decided to briefly post.

I had to do a number of things to the ./configure line. Like POK, I had to add:

-build=i686-apple-macos

and

CFLAGS=-I/usr/include/malloc

I also had to identify my X11 library and headers:

 LDFLAGS=-L/opt/X11/lib CFLAGS=-I/opt/X11/include

Now, for some reason the first time I got it to work, I had multiple CFLAGS arguments and it worked fine:

./configure -build=i686-apple-macos LDFLAGS=-L/opt/X11/lib CFLAGS=-I/opt/X11/include  CFLAGS=-D'ARCH="darwin"' CFLAGS=-I/usr/include/malloc

The second time, however, that failed, and I figured out that I had to consolidate them:

./configure -build=i686-apple-macos LDFLAGS=-L/opt/X11/lib CFLAGS='-I/opt/X11/include -I/usr/include/malloc'

Still haven't figured out why it appeared to work the first time. It's possible I manually edited the makefiles and then forgot, but I really don't think so.

Now, about that D'ARCH="darwin"...

For some reason, everything else was working but HTKLib/HGraf.c was complaining that it contained the variable ARCH which it had never heard of. The installation info on the HTK download site showed that variable being automatically set, but I couldn't get it to work; I actually had to go into HTKLib/HGraf.c and change variable ARCH to string "darwin". Not good to have to do that, but it seemed to get me up and running, so I'm happy as long as I remember how to do it next time...hence this blog post :)

So now I'm back to happily working through the tutorial in HTKBook...oh goodie. My first grammar-related seg fault. :D

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. instead of changing the source, you could define the ARCH in the configure step with:
    -DARCH="darwin"
    that is for the complete configure step:
    ./configure -build=i686-apple-macos LDFLAGS=-L/opt/X11/lib CFLAGS='-I/opt/X11/include -I/usr/include/malloc -DARCH=\"darwin\"'

    ReplyDelete
  3. It looks to me as though at least part of the problem lies in ./configure. configure sets the flags by looking at the host type. For most architectures, the host type is specified with wild cards (e.g. "*x86_64*linux*"), but for Macs it's specified just as "darwin"). But my host type is "i386-apple-darwin10.8.0", which isn't the same as "darwin", so it's ignored and the relevant flags don't get set. If you change "darwin" to "*darwin*" in configure then you're most of the way there.

    But you're not quite there, because you still have to tell the C compiler that you're on a 32-bit machine. If you change the line

    CFLAGS="-ansi -g -O2 -DNO_AUDIO -D'ARCH=\"darwin\"' $CFLAGS"

    to

    CFLAGS="-ansi -g -O2 -m32 -DNO_AUDIO -D'ARCH=\"darwin\"' $CFLAGS"

    then you're very nearly there. It still doesn't compile hlmtools for me (I get "No rule to make target `HLMLib.a'"), but since all I want is htktools that doesn't bother me.

    ./configure
    make htktools
    make install-htktools

    works for me with the changes above

    ReplyDelete
  4. (sorry, that should have been '... change "darwin" to "*darwin*" ...')

    ReplyDelete
  5. Hello,
    When I typed "make" I got the following warning but I don't understand why I got that error

    make
    (cd HTKLib && /Applications/Xcode.app/Contents/Developer/usr/bin/make HTKLib.a) \
    || case "" in *k*) fail=yes;; *) exit 1;; esac;
    gcc -ansi -g -O2 -DNO_AUDIO -D'ARCH="darwin"' -I/usr/include/malloc -Wall -Wno-switch -g -O2 -I. -DPHNALG -c -o esig_asc.o esig_asc.c
    gcc -ansi -g -O2 -DNO_AUDIO -D'ARCH="darwin"' -I/usr/include/malloc -Wall -Wno-switch -g -O2 -I. -DPHNALG -c -o esig_edr.o esig_edr.c
    esig_edr.c:1192:60: warning: '&&' within '||' [-Wlogical-op-parentheses]
    if (hi > lmaxhi || hi == lmaxhi && lo > lmaxlo)
    ~~ ~~~~~~~~~~~~~^~~~~~~~~~~~~~
    esig_edr.c:1192:60: note: place parentheses around the '&&' expression to silence this
    warning
    if (hi > lmaxhi || hi == lmaxhi && lo > lmaxlo)
    ^
    ( )
    esig_edr.c:1204:60: warning: '&&' within '||' [-Wlogical-op-parentheses]
    if (hi < lminhi || hi == lminhi && lo < lminlo)
    ~~ ~~~~~~~~~~~~~^~~~~~~~~~~~~~

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete