Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access a Linux gcc compiled .so shared library from Windows Mono C# Project

Here's the setup:

I've got a shared library (c++ with extern "C" methods) I've compiled in linux and created a library.so file.

I've used Mono Develop on the same box (Ubuntu) and was able to DLLImport("library.so") and access my extern functions no problem.

The problem comes in when I copied that .so file to a windows machine (Win7) and I try to do the same thing, but this time running Mono under windows with MonoDevelop.

I get a System.BadImageFormatException. I've tried doing a "./" before the library.so file, but nothing helps. I've checked and double checked that it's looking at the right directory and it is.

Is there something big I'm missing why I can't access this .so file under Windows/Mono?

like image 387
Nick Avatar asked Dec 28 '22 05:12

Nick


1 Answers

You can't use a .so elf binary on Windows for your native code. You need to recompile it into a native binary supported by Windows (namely a .dll).

I suggest you read our wiki page about cross platform interop between managed an unmanaged code.

like image 76
Jb Evain Avatar answered Jan 30 '23 20:01

Jb Evain