The SPDK build system generates pkg-config files to facilitate linking applications with the correct set of SPDK and DPDK libraries. Using pkg-config in your build system will ensure you do not need to make modifications when SPDK adds or modifies library dependencies.
If your application is using the SPDK nvme library, you would use the following to get the list of required SPDK libraries, and the DPDK libraries for the DPDK-based environment layer:
When linking with static libraries, the dependent system libraries must also be specified. To get the list of required system libraries:
Note that SPDK libraries use constructor functions liberally, so you must surround the library list with extra linker options to ensure these functions are not dropped from the resulting application binary. With shared libraries this is achieved through the -Wl,--no-as-needed
parameters while with static libraries -Wl,--whole-archive
is used. Here is an example Makefile snippet that shows how to use pkg-config to link an application that uses the SPDK nvme shared library:
If using the SPDK nvme static library, you should also wrap with -Wl,-Bstatic
and -Wl,-Bdynamic
. DPDK by default builds both shared and static libraries - these linker args will ensure that linker uses the static versions: