Skip to content

[c/c++] minimal cc/ld wrapper instead of LD_LIBRARY_PATH #104

@Mic92

Description

@Mic92

LD_LIBRARY_PATH breaks users' executable in the following ways:

  • Executables not part of devshell might pick up libraries from LD_LIBRARY_PATH, this can lead to incompatible libraries being loaded and crash executables. This is very likely to happen on NixOS with different release channels or on Non-NixOS distributions
  • Executables compiled in devshell won't run if the environment is unset or users tries to start them outside of devshell

Instead a minimal cc/ld wrapper could set an rpath and interpreter:

#!/usr/bin/env bash
exec /nix/store/xxxxx-gcc-unwrapped/bin/gcc -Wl,-rpath=$DEVSHELL_ROOT/lib" -Wl,-dynamic-linker=$NIX_DYNAMIC_LINKER "$@"
#!/usr/bin/env bash
exec /nix/store/xxxxx-binutils-unwrapped/bin/ld -rpath "$DEVSHELL_ROOT/lib" -dynamic-linker "$NIX_DYNAMIC_LINKER" "$@"

Dynamic linker can be obtained from the wrapped version at build time: $(cat $NIX_CC/nix-support/dynamic-linker)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions