Using lldb on nixos

How can I use lldb on nixos for my c project? When I run my project using clang -g -o main main.c and then try running lldb main, I get this error:

/nix/store/l2iidv87qb7gfdafd5s3fg3hc1h869qp-lldb-16.0.6/bin/lldb: error while loading shared libraries: libclang-cpp.so.16: cannot open shared object file: No such file or directory. How can I get lldb to work on my system? This is my current flake.nix file:

  description = "Clang development environment";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (
      system:
        let
          pkgs = import nixpkgs { inherit system; };
          llvm = pkgs.llvmPackages_latest;
          lib = nixpkgs.lib;
        in
          {
            devShell = pkgs.mkShell {
              nativeBuildInputs = [
                pkgs.cmake
                llvm.lldb
                pkgs.clang-tools
                llvm.clang
                pkgs.gtest
              ];
              buildInputs = [
                llvm.libcxx
              ];
              CPATH = builtins.concatStringsSep ":" [
                (lib.makeSearchPathOutput "dev" "include" [ llvm.libcxx ])
                (lib.makeSearchPath "resource-root/include" [ llvm.clang ])
              ];
            };
          }
    );
}
1 Like