Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Library Search Path for External Unmanaged DLLs

Discussion in 'Scripting' started by kiddsck, Jul 12, 2020.

  1. kiddsck

    kiddsck

    Joined:
    Oct 10, 2019
    Posts:
    2
    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?
     
  2. kiddsck

    kiddsck

    Joined:
    Oct 10, 2019
    Posts:
    2
    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.
     
    PraetorBlue likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Finally, it is broken! Rejoice!