首页 > 解决方案 > 如何用 nix 测试共享库?

问题描述

我有以下推导:

{ stdenv
, cmake
, python38
, enableCfp ? false
, enableZforp ? false
, enableZFPy ? false
, enableUtilities ? true
, enableExamples ? false
, enableTestingSmall ? true
, enableTestingLarge ? false
, enableSharedLibs ? true
}:

let
  # FIXME: Pretty sure this should use buildPythonPackage or something
  pythonEnv = python38.withPackages (ps: [
    ps.cython
    ps.numpy
  ]);
in
stdenv.mkDerivation rec {
  pname = "zfp";
  version = "0.5.5";
  src = builtins.fetchTarball {
    url = "https://computing.llnl.gov/projects/floating-point-compression/download/zfp-0.5.5.tar.gz";
    sha256 = "1l9skghq2iyj4h4ql9z49rqm07bvins6bff0cg8nmfnhp5inww33";
  };

  doCheck = enableTestingSmall || enableTestingLarge;

  cmakeFlags = []
    ++ stdenv.lib.optional enableCfp "-DBUILD_CFP=ON"
    ++ stdenv.lib.optional enableZforp "-DBUILD_ZFORP=ON"
    ++ stdenv.lib.optional enableZFPy "-DBUILD_ZFPY=ON"
    ++ stdenv.lib.optional (!enableUtilities) "-DBUILD_UTILITIES=OFF" # Default on
    ++ stdenv.lib.optional enableExamples "-DBUILD_EXAMPLES=ON"
    ++ stdenv.lib.optional (!enableTestingSmall) "-DBUILD_TESTING_SMALL=OFF" # Default on
    ++ stdenv.lib.optional enableTestingLarge "-DBUILD_TESTING_LARGE=ON"
    ++ stdenv.lib.optional (!enableSharedLibs) "-DBUILD_SHARED_LIBS=OFF"
    ++ stdenv.lib.optional (!doCheck) "-DBUILD_TESTING=OFF";

  nativeBuildInputs = [ cmake ]
    ++ stdenv.lib.optional enableZFPy pythonEnv;
}

虽然它生成了正确的库,但测试似乎没有使用它们。我得到:

/build/source/build/nix/store/iay9p2wvwrv3x2352qwk0jhbpkx45ibl-zfp-0.5.5/bin/testzfp: error while loading shared libraries: libzfp.so.0: cannot open shared object file: No such file or directory

应该如何将生成的库包含在 LD_LIBRARY_PATH(?)

谢谢。

标签: unit-testingtestingautomated-testsnixnixos

解决方案


推荐阅读