How to solve libstdc++ not found in shell.nix


I am trying to run nix-shell to use poetry (and hopefully poetry2nix). I am stuck with an error from an executable from a python package that claims libstdc++ is missing.

I’ve found something that looks like a solution on Packaging/Quirks and Caveats - NixOS Wiki (linked from What package provides
but it is for packaging and not nix-shell.

With nix-shell I get the error

error: undefined variable 'stdenv'

       at /home/espen/code/python-fmri-env/shell.nix:11:23:

           10|     # fixes libstdc++ issues
           11|     LD_LIBRARY_PATH=${}/lib/
             |                       ^
           12|     '';

So how to I refer to this variable in shell.nix? I’ve tried to add stdenv like { stdenv, pkgs ? import … } but no luck. I need it to work both on Nix and on NixOS.


{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {

  buildInputs = [
  shellHook = ''
    # fixes libstdc++ issues and issues

EDIT: clarity and mistakes

1 Like

stdenv is in pkgs, so just use


Thank you!

shell.nix now evaluates, but unfortunately I still get the same error. Seems like the solution I linked to wasn’t enough.

The error message I get is:

(python-fmri-env-py3.10) espen@mainframe-ubuntu:~/code/python-fmri-env$ clinica
Traceback (most recent call last):
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/bin/clinica", line 5, in <module>
    from clinica.cmdline import main
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/clinica/", line 13, in <module>
    from clinica.iotools.converters.cli import cli as convert_cli
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/clinica/iotools/converters/", line 5, in <module>
    from .habs_to_bids import habs_to_bids_cli
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/clinica/iotools/converters/habs_to_bids/", line 5, in <module>
    import clinica.iotools.bids_utils as bids
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/clinica/iotools/", line 7, in <module>
    from pandas import DataFrame
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/", line 48, in <module>
    from pandas.core.api import (
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/", line 47, in <module>
    from pandas.core.groupby import (
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/groupby/", line 1, in <module>
    from pandas.core.groupby.generic import (
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/groupby/", line 76, in <module>
    from pandas.core.frame import DataFrame
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/", line 172, in <module>
    from pandas.core.generic import NDFrame
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/", line 169, in <module>
    from pandas.core.window import (
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/window/", line 1, in <module>
    from pandas.core.window.ewm import (
  File "/home/espen/.cache/pypoetry/virtualenvs/python-fmri-env-5taD3dGB-py3.10/lib/python3.10/site-packages/pandas/core/window/", line 15, in <module>
    import pandas._libs.window.aggregations as window_aggregations
ImportError: cannot open shared object file: No such file or directory

I get the same error both with Ubuntu/Nix and NixOS. Any ideas how to fix this?

it might be because that LD_LIBRARY_PATH is not exported


Amazing, that works! Good catch!

Just a word of warning.

There are circumstances under which the shellhooks are not effective.

You should prefer to set envvars via attributes whenever possible, as that is more reliavble.

1 Like

Thanks for the warning. How would I define the library path through an attribute?

1 Like

If you could point me in the direction where I should look in the documentation that would also be great.

mkShell {
  LD_LIBRARY_PATH = "${}/lib";

Thank you, this solved a longstanding problem for me. Just for completness and for everybody who comes after me (especially myself a few weeks in the future), here is a complete shell.nix that works for me (you probably don’t need the unstable part):

  unstable = import (fetchTarball "\
448a599c499/nixexprs.tar.xz") { };
{ nixpkgs ? import <nixpkgs> {} }:

nixpkgs.mkShell {
  nativeBuildInputs = with nixpkgs; [

  LD_LIBRARY_PATH = "${}/lib";

It took 3 months, but it was worth it.

1 Like

This has worked to me:

  environment = {
    sessionVariables = {
      LD_LIBRARY_PATH = "${}/lib";

No, please give What package provides - #5 by NobbZ a read.

1 Like

What’s the difference between this and your own suggestion?

That you put it into the global environment, rather than a dev shell.

For other readers, especially if you have multiple libraries you might consider lib.makeLibraryPath, which will combine its inputs properly and add the /lib for you. For example:

pkgs.mkShell {
    LD_LIBRARY_PATH = lib.makeLibraryPath [ ];

is there a way to check the versions going into like if I need libstdc++ to be >= 7.1`

Thanks, this works for me.