Cannot link against Python

Hi,
I’m creating a derivation for qiskit-aer, a quantum computer simulator.
qiskit-aer is written in C++ and compiled using CMake.
Also, it has a Cython wrapper for using it from Python.
Since this module requires to be linked against Python, I used NIX_CFLAGS_COMPILE and NIX_LDFLAGS as follows:

{ stdenv
, isPy3k
, buildPythonPackage
, fetchFromGitHub
, cmake
, blas
, liblapack
, scikit-build
, cython
, python
}:

buildPythonPackage rec {
  pname = "qiskit-aer";
  version = "0.1.1";

  disabled = !isPy3k;

  src = fetchFromGitHub {
    owner = "Qiskit";
    repo = "qiskit-aer";
    rev = "21fdd7e7503dc8ac7dfaee24b927f26d1eff42f8";
    sha256 = "1p4w1jg6sl9xvmp98nrn5s6drp1rcl67vzi5xdh639kf498y49nz";
  };

  buildInputs = [
    scikit-build
    cython
    cmake
    blas
    liblapack
  ];

  NIX_CFLAGS_COMPILE = [
    "-I${python.outPath}/include/${python.executable}"
  ];

  NIX_LDFLAGS = [
    "-L${python.outPath}/lib"
  ];
}

I can compile the sources, but link fails because Python library is missing.
The error message is:

[ 45%] Linking CXX shared module statevector_controller_wrapper.cpython-37m-x86_64-linux-gnu.so
/nix/store/3xwc1ip20b0p68sxqbjjll0va4pv5hbv-binutils-2.30/bin/ld: cannot find -lpython3.7m
collect2: error: ld returned 1 exit status

although I have libpython3.7m.so in the directory I specified:

[pan@pan-nixos:~/nixpkgs]$ ls /nix/store/6lm4gi5iv8fbf1b1mm6g3gfnnv63f1gn-python3-3.7.1/lib/
libpython3.7m.so  libpython3.7m.so.1.0  libpython3.so  pkgconfig  python3.7

How to build a package that link against Python?

If you want to test the code, you can fetch the following branch (qiskit-0.7.1):

Since qiskit-aer uses scikit-build for invoking cmake during the setup, I included scikit-build.

1 Like

It seems https://github.com/NixOS/nixpkgs/pull/54486 fixes this issue.
After I cherry-picked it and https://github.com/NixOS/nixpkgs/pull/54890, I can build the package.