Search code examples
c++.netlinuxshared-librarieswine

DLLNotFound when using DLLImport with shared library


I am creating a .NET Framework 4.0 application that use a DLL when launch on Windows and a shared library wrote in C++ when launch on Linux (debian version 10).

The C# codes looks like that :

[DllImport("graf")]
private static extern int Method1();

On Windows, everything is fine, and the application works very well. On Linux, I use Wine to start the application. The problem is that when i try to use any method from my library, I got a DLLNotFoundException: graf.

My shared library is in /lib, /usr/lib and in the exe folder. I tried with renaming my libraries libgraf.so and only graf.dll but it's not working.

I followed every step of this link. But I can't use my .so library.

Do you have any clue to fix that ?

EDIT: Ok it's seems to be a problem in my shared library compilation.


Solution

  • My problem came from the fact that 1) my library was badly compiled (Makefile problem); and 2) I had to use the keyword extern "C" { in the definitions of my functions.

    See What is the effect of extern "C" in C++? for more details.