A transitive dep (a C++ lib) compiled with wrong flags, how can be overridden

Sorry, I am a newby with nix (using the package manager under darwin) and the forum.

I am trying to create a flake.nix for a c++ project. The main goal is to use a nix develop shell for development. This is how I instatiate the shell within the flake

    devShells.default = pkgs.mkShell.override { stdenv = pkgs.gcc12Stdenv; } rec {
      name = "my-c++-project";

      packages = with pkgs; [
        cmake
        ninja

        gtest

        spdlog
        abseil-cpp
      ];

  });

As you can see, I am trying to use gcc-12 (on darwin).
The problem is that spdlog brings in a fmt library which at link time gives this error:

Undefined symbols for architecture arm64:
  "__ZN3fmt2v87vformatB5cxx11ENS0_17basic_string_viewIcEENS0_17basic_format_argsINS0_20basic_format_contextINS0_8appenderEcEEEE",

which is the same to say that the following is missing:

fmt::v8::vformat[abi:cxx11](fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)

So probably, the fmt lib was compiled with the wrong C++ ABI, and the question finally is: how can override the way fmt is being compiled?

1 Like

In your case the stdenv change doesn’t trickle down into your used pkgs,
see also here:
https://groups.google.com/g/nix-devel/c/T8YlEcJj1G0
ans here:

3 Likes

Indeed if I do the following

nix-repl> :b fmt_8.override { stdenv = gcc12Stdenv; }

This derivation produced the following outputs:
  dev -> /nix/store/lf28igdjc230mrgs1d000qy5cfcyjlf1-fmt-8.1.1-dev
  out -> /nix/store/y85s6w89vcs08k1n4gqrr4dnnvqqv01q-fmt-8.1.1

And if you check the corresponding library, you can see the correct symbol exported

/nix/store/y85s6w89vcs08k1n4gqrr4dnnvqqv01q-fmt-8.1.1/lib ⌚ 18:49:55
$ nm --demangle --defined-only  libfmt.8.1.1.dylib | grep abi
00000000000175e0 T fmt::v8::vformat[abi:cxx11](fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)

I am still struggling to write a decent override in the flake.nix without getting strange errors, but at least I have a clue now. Thanks