What is the correct way to add libraries so what linker could find them?

I’m trying to create nix-shell environment to build my c++ project which includes static aws-core libraries. These static libraries have dependencies and I’m trying to fulfill them.
Right now my .nix file looks like this:

with import {}; {
qpidEnv = gcc48.stdenv.mkDerivation {
name = “my-gcc4.8-env”;
nativeBuildInputs = [ cmake pkgconfig ];
buildInputs = [ hiredis c-ares gcc48 cmake libev libevdev zlib openssl krb5 e2fsprogs ];
LD_LIBRARY_PATH = “${krb5}/lib”;
};

Error I get is that linker doesn’t find libcom_err* object files which are in e2fsprogs library.

I have tried launching nix-shell with -p e2fsporgs and what solved libcom_err part, but ruined krb5 libraries part.

So my question is, what is the correct way to add libraries so what linker could find them?

It probably depends from build system to build system. In your example
above it seems like your are using CMake. CMake is capable of asking
pkg-config (pkg-config) for
the corret cflags and ldflags required to use some library as part of
your application.

Most libraries in nixpkgs support pkg-config and thus that should be the
“best” way of implementing this.

Under the hood each of these dependencies adds a lookup path to the
environment variable PKG_CONFIG_PATH.

1 Like

How could I transfer PKG_CONFIG_PATH to LD_LIBRARY_PATH so what linker could find these libraries then?