Install the C API

Prerequisites

Before getting started, you must ensure that you have installed the Rust toolchain as well as the clang compiler.

Now, clone the qiskit-fermions repository.

git clone git@github.com:Qiskit/qiskit-fermions.git
cd qiskit-fermions

Next, you must also compile the Qiskit C API. You can do this in any location, but to get started quickly, follow these steps:

git clone git@github.com:Qiskit/qiskit.git build/qiskit
cd build/qiskit
## git-checkout the latest stable tag
make c

Hint

On Windows only, you need to copy additional library files:

cp target/release/qiskit_cext.dll dist/c/lib/qiskit_cext.dll
cp target/release/qiskit_cext.dll.lib dist/c/lib/qiskit_cext.dll.lib
cp target/release/qiskit_cext.dll.lib dist/c/lib/qiskit.dll.lib

Now you can follow the steps in the next section to compile the qiskit-fermions C API.

Compile from source

To get started, configure your shell environment with the locations of your compiled Qiskit C API library and include directory.

Important

The C API links against the Qiskit C library, so QISKIT_LIB and QISKIT_INCLUDE must resolve to it. If unset, the build attempts to infer them from any installed qiskit Python package which bundles its C artifacts (qiskit.capi.get_lib()/get_include()); set them explicitly, as below, to build against a separately compiled Qiskit C API such as the build/qiskit clone above.

Hint

This code uses the build/qiskit path from the code at the top of this page. Adjust the paths according to your setup.

export QISKIT_LIB=$(find $(pwd)/build/qiskit/dist/c/lib -name "libqiskit.*")
export QISKIT_INCLUDE=$(pwd)/build/qiskit/dist/c/include
export QISKIT_LIB=$(find $(pwd)/build/qiskit/dist/c/lib -name "qiskit_cext.dll.lib")
export QISKIT_INCLUDE=$(pwd)/build/qiskit/dist/c/include

Now, compile the qiskit-fermions C API:

make cext

If you want to test your installation, you now must also install CMake. You can then test your compilation by running the C unit tests:

make testc

Finally, verify that you see these relevant files:

  • dist/c/lib/libqiskit_fermions.so (The suffix might vary depending on your operating system)

  • dist/c/include/qiskit_fermions.h