adding custom library on a .NET project thanks to torizon extention on vs code

Hi,

I had to perform specific operations on memory for a .NET project. So I built a custom shared library that contains the methods I need (they don’t exists on .NET).

the name of my lib is libcomeim.so

I’m now trying to add libcomeim.so on my .NET project. But I don’t know how to do that with the torizon extension for vs code.

I already tried to add this on the path : obj\Debug\net5.0linux-arm\libcomeim.so
But when I run this code:

using System.Runtime.InteropServices;


namespace teestt
{
    class Program
    {

        [DllImport ("libcomeim.so")]
        private static extern void test();

        static void Main(string[] args)
        {

            test();

            
        }
    }
}

The following exception appears:

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'libcomeim.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibcomeim.so: cannot open shared object file: No such file or directory
   at teestt.Program.test()
   at teestt.Program.Main(String[] args) in C:\Users\rfonc\Desktop\docs_stage\code\teestt\Program.cs:line 16

Have you an idea about how I can add mpy shared library to my project ?

Best regards,
rfonck

Greetings @rfonck,

Just to make sure I understand your situation. So you already have your shared library binary pre-compiled. Now you want to add this binary to a .NET project such that the application there can access it correct?

It appears you already made an initial attempt. Could you describe your procedure for this attempt?

Best Regards,
Jeremias

You can add your library to your project contents, as described there.
This will put it in your output folder, and deploy it together with the rest of the application.
The you may set the env configuration property to:
ENV LD_LIBRARY_PATH=“$LD_LIBRARY_PATH:/#%application.appname%#/lib”

(you may change /lib to the sub-path of your application output folder where you put the library file)