Library Search Path for External Unmanaged DLLs

I have a problem where my code actually works, and I’m not sure why.

I have a C# managed DLL that I drop into my assets folder and call from my Unity C# project. That is all well and good. Within the DLL there is a reference to an external C library (libmkl_rt.dylib, an intel MKL dll installed at /opt/intel/mkl/lib). Now when I run the code that’s in the C# DLL separate from Unity (in VB 2019 or as an exe on the console), if I do not set my DYLD_LIBRARY_PATH to include external C library address, I get a ‘dll not found’ error. However when I run the same code in Unity (hit the play button and a game object runs the code), the code runs fine.

First of all, where does Unity look for DLLs, i.e. what are the library search paths and where do you set them? Does setting the DYLD_LIBRARY_PATH in a shell on the terminal effect anything that Unity does? How is Unity finding this DLL?

I have an update. I converted the project to 2019.4.4f1 from 2018.4.9f1. Now Unity throws a dll not found error! If I softlink to the libmkl_rt.dylib from the assets directory, then my script runs in 2019 (no dll error). I have no idea how 2018 was finding the necessary dylib without any link and 2019 does not. But the 2019 behavior is what I expected, and the world makes sense again.

1 Like

Finally, it is broken! Rejoice!