Skeleton Makefile for Kaldi Projects

Here is a short Makefile that will set th compiler options to allow programs to compiled and linked against your Kaldi installation. This is portable on the filesystem and new programs do not need to placed in a subdir of Kaldi's src dir. Once the KALDI_ROOT variable is set everything should just work. Depending on the libraries the linker options will need changing.

KALDI_ROOT=

all: something-using-kaldi

ifndef KALDI_ROOT
$(error KALDI_ROOT is not set)
endif


include $(KALDI_ROOT)/src/kaldi.mk
CXXFLAGS+=-I${KALDI_ROOT}/src/

something-using-kaldi: something-using-kaldi.o
  $(CXX)  $^ -o $@  $(LDFLAGS) $(LDLIBS) $(KALDI_ROOT)/src/lat/kaldi-lat.a \
    $(KALDI_ROOT)/src/base/kaldi-base.a   $(KALDI_ROOT)/src/util/kaldi-util.a

clean:
  rm -rf *.o something-using-kaldi

%.o:%.cc
  $(CXX) $(CXXFLAGS) -c $<

%.o:%.cpp
  $(CXX) $(CXXFLAGS) -c $<

The hard tabs in the above code have been replaced with spaces. Here is gist to minimal working example that converts Kaldi lattices to HTK's SLF format.