Monday, January 15, 2018

Build HTK on macOS with Minimum Effort

In the last post, I presented instructions to build HTK on Ubuntu. In this post, I will show you how to compile HTK on macOS.

As before, download HTK latest stable version source code, 3.4.1 at the time of writing, from here. Extract the files as usual.
$ tar xfz HTK-3.4.1.tar.gz
$ cd htk

Next, you need some required software tools from Apple.
$ xcode-select --install

Now, let's configure and make
$ ./configure --prefix=$(pwd)
$ make

You will probably encounter an error complaining
(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 HGraf.o HGraf.c
HGraf.c:73:10: fatal error: 'X11/Xlib.h' file not found

There are two options here. The first is to simply skip HSLab package that requires X11, thereby building without X11.
$ ./configure --prefix=$(pwd) --disable-hslab
$ make
$ make install

You will see all binary files in the bin folder.


The other option is to install X11 library. Download XQuartz from here and install it. This will create /opt/X11/ folder with necessary library and header files. We can now manually compile HTKLib package by specifying the header files
$ cd HTKLib
$ gcc  -ansi -g -O2 -DNO_AUDIO -D'ARCH="darwin"' -I/usr/include/malloc -Wall -Wno-switch -g -O2 -I. -DPHNALG   -c -o HGraf.o HGraf.c -I /opt/X11/include
$ cd ..

We also need to set library path:
$ export LIBRARY_PATH=/opt/X11/lib

Now, we are ready to resume the make process
$ make
$ make install

Viola! You should see bin directory with all HTK binary files!

3 comments:

  1. 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
  2. Hello, wondering if you can help me as well. After taking care of the Hgraf.c problem where it displays

    'X11/Xlib.h' file not found

    I receive a new error:

    $ make -f MakefileCPU all
    gcc -m64 -ansi -std=gnu99 -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH="x86_64"' -Wall -Wno-switch -g -O2 -I. -DPHNALG -I/opt/X11/include -c -o HAudio.o HAudio.c
    HAudio.c:141:10: fatal error: 'sys/soundcard.h' file not found
    #include
    ^~~~~~~~~~~~~~~~~
    1 error generated.
    make: *** [HAudio.o] Error 1

    I'm new with the specifics of how my computer is built. Haven't found much information about 'soundcard.h' which yields a nice answer. Wondering if any of you know anything. Thank you in advance. I tried to download the beta version: HTK 3.5. I will try with the stable version.

    ReplyDelete
  3. thank you for an excellent and helpful bit of instruction! it finally worked.

    one tweak, though. it still gave me an error, even after installing X11, with the compile breaking on malloc.h in HTKLib/strarr.c. The fix is to find the line which #include and change it to #include

    ReplyDelete