0

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.

  • Have you read the documentation yet? [Writing cross platform P/Invoke code](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/cross-platform) – Remy Lebeau May 19 '22 at 19:17
  • Yes, but it's not much different from the link I read about. The problem remains the same, the .so library is not found by the program. Do you think that it can come from Wine (or mono) – Yanis Miollany May 20 '22 at 07:44

1 Answers1

0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770