Search Unity

Question How to use .so libraries in a Unity project?

Discussion in 'Linux' started by lauchsuppe, Mar 2, 2021.

  1. lauchsuppe

    lauchsuppe

    Joined:
    Dec 6, 2014
    Posts:
    39
    I am trying to use Microsoft Azure Kinect in my Unity project. I'm running Ubuntu 18.04.
    I successfully installed the Azure Kinect SDK on my system. Afterwards, I copied over the installed .so files from my library (usr/lib/) to my Unity project (Assets/Plugins/x86_64/). They get recognized as plugins by the Unity inspector.

    What I'm expecting is that I can now use them in my scripts with a using directive, e.g. "using libXYZ;". In the same way that on Windows, I would be able to use them like "using Microsoft.Azure".

    Unfortunately, I'm getting a compile error when trying to use the copied .so files like that as they are not being recognized/ cannot be found.

    This might be an error on my side, as I am not very experienced with Linux in general. But I don't understand what I am doing wrong or what I am supposed to be doing instead. My question is, how to correctly import these libraries so I can use them?

    Any help would be greatly appreciated!
     
  2. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    Hi @lauchsuppe. Sounds like these are native binaries. In that case, you can't use them in C# code without using P/Invoke. Basically, for each exported function you intend to use, you need to create a wrapper function for it that tells managed code how to marshal the data to and from the native library.

    It looks like some pre-baked wrappers are available if you follow the instructions in README.md at the Unity sample in the Azure-Kinect-Samples repository. You'll have to install nuget in order to download the packages, and I don't know if the wrappers have been tested for Linux or not.
     
  3. lauchsuppe

    lauchsuppe

    Joined:
    Dec 6, 2014
    Posts:
    39
    Thank you so much for pointing me in the right direction! Unfortunately, after downloading the packages and placing them in the project, it's still not working. So, I suppose the SDK is just not compatible with Unity on Linux.