Library I'm trying to package expects static libraries

I’m trying to package this speech recognition library which is a fork of kaldi and a dependency for a dictation program I want to try out. It requires either MKL or OpenBLAS. If I try to use MKL, it will complain that it can’t find libmkl_intel_lp64.a. MKL from nixpkgs instead provides libmkl_intel_lp64.so. It’s the exact same situation with OpenBLAS. I’m not a C/C++ programmer, but I understand that the .a versions are static libraries, right? Is there anyway to make use of MKL or OpenBLAS from nixpkgs in my derivation for the fork of kaldi?

Alternatively, that library includes scripts for installing OpenBLAS and MKL. If I try to use the one for installing OpenBLAS, I end up with errors that look like this

/nix/store/3b3ighb83nhifa1v4n7855hlbdl1mhf9-binutils-2.31.1/bin/ld: /nix/store/9cyy1lisy7gh44i9mqcmwlrkpiqbgwjw-gfortran-9.3.0/lib/libgfortran.a(read.o): relocation R_X86_64_32S against `.rodata.masks.13171' can not be used when making a shared object; recompile with -fPIC
/nix/store/3b3ighb83nhifa1v4n7855hlbdl1mhf9-binutils-2.31.1/bin/ld: final link failed: nonrepresentable section on output

That was using this derivation:

with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "kaldi-fork-active-grammar";
  src = fetchgit {
    url = "https://github.com/daanzu/kaldi-fork-active-grammar";
    rev = "3f56242df335792756ca17f46a348ca2b36238d7";
    sha256 = "1fmyzyxb94br0kxdfczrhdv2f25zz71a96r8brbzbqmwcjlkpm0j";
  };
  buildInputs = [ zlib automake autoconf subversion sox gfortran gfortran.cc libtool python27 openfst ];
  postPatch = ''
    mkdir -p python && touch python/.use_default_python && tools/extras/check_dependencies.sh
    find . -type f | xargs -i@ sed -i 's:/bin/bash:${stdenv.shell}:g' @
    sed -i '1069s/.*/OPENFST_VER=1.7.4/' src/configure
  '';
  postConfigure = ''
    (
    cd tools
    make -j4 && \
    make -j openblas
    ) && \
    (
    cd src
    ./configure --shared --static-math --mathlib=OPENBLAS --fst-root=${openfst} && \
    make -j4 depend && make -j4 dragonfly dragonflybin bin fstbin lmbin
    )
  '';
}

It fails at make -j openblas in postConfigure. The build process is based on the build commands here, in a separate project.

1 Like

Maybe you can try the pkgsStatic attribute set?

Also, if you are planning to PR this, use pname, version and fetchFromGitHub.

Hey thanks, I didn’t know about that! But this is weird. I added pkgsStatic.openblas to buildInputs in place of openblas, and used the configure flag --openblas-root=${pkgsStatic.openblas}. But then I got

***configure failed: Expected to find the file /nix/store/ni2svwymdjhgd5ssnyprnklnv05ij4d7-openblas-0.3.8-x86_64-unknown-linux-musl/lib/libopenblas.so ***

So it requires both the static library and the shared object file? Is that normal?

I would guess this would as for the static library.

Ugh, the configure script is messy.

You can also try the CMake build system – just add cmake to buildInputs and various flags to cmakeFlags:

1 Like