Taking a look [at the man page for dlopen(3)](http://man7.org/linux/man-pages/man3/dlopen.3.html), I think the easiest thing to do would to be to wrap the dlopen() call in the Nim code in something that sets and then resets the LD_LIBRARY_PATH environment variable.
Taking a look at the dlopen() imports in [dylib.nim](https://github.com/nim-lang/Nim/blob/75345ad1aacf8e2a4d43e4e89f16f6a641d6a9c3/lib/pure/dynlib.nim#L85) and [dyncalls.nim](https://github.com/nim-lang/Nim/blob/7e351fc7fa96b4d560c5a51118bab22abb590585/lib/system/dyncalls.nim#L67), we could use the os modules' getEnv() and putEnv() functions. E.g.: from os import getEnv, putEnv proc real_dlopen(path: cstring, mode: cint): LibHandle {.importc: "dlopen", header: "<dlfcn.h>".} proc dlopen(path: cstring, mode: cint): LibHandle= # Modify the library search path var origLibPath = getEnv("LD_LIBRARY_PATH") newLibPath = originalLibPath & ":/usr/local/lib" setEnv("LD_LIBRARY_PATH", newLibPath) result = real_dlopen(path, mode) setEnv("LD_LIBRARY_PATH", origLibPath) I think that would do it. Looking also [at OS X's dlopen()](https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/dlopen.3.html), it might be best to add in a block that will get the correct environment variable to get, set, and reset. Interestingly enough, OS X already searches /usr/local/lib by defualt. But I'm not sure about /usr/local/Cellar, where is where homebrew likes to put stuff. I'll leave the details up to you, but I think this needs to be the case for Linux at least.