How can I provide libpcre to a build outside of Nix?

I’m working on a project built with Nim that requires libpcre. There is no point in Nix-ifying it because it’s an external project that I just want to build to verify my change works.

I tried setting LD_LIBRARY_PATH:


But it doesn’t help:

/nix/store/ cannot find -lpcre

What is the proper way of providing a library to a local build that isn’t a derivation?

You should consider building insude a nix developpment environment, a.k.a a nix shell, from the nix-shell command used to do so.

$ nix-shell -p pcre # or pcre2, pcre-cpp, as you wish
[nix-shell:~]$ ./confiugure; make # or whatever nim requires

You should stuff all your dependencies on that invocation. Like gcc, nim and the like. If you feel lucky, add the --pure argument to the nix-shell invocation. This will hide your global environment, and thus fail if you missed dependencies on the command line.

If you are curious, have a look at all the environment variables that nix-shell changes with this zsh command:

git diff --no-index  =(env | sort) =(nix-shell -p pcre --command env | sort)
1 Like

You’re absolutely right. I managed to build the project using:

nix-shell --pure -p gcc nim pcre which


gcc shouldn’t be necessary in your nix-shell as it implicitly gets introduced through stdenv

IIRC, LD_LIBRARY_PATH is to modify the runtime linking behavior, and wouldn’t affect a build

1 Like

Ah, good point. Thanks!