Lazlo
Lazlo

Reputation: 8790

Mono DLL to open appropriate Windows/Mac DLL/DyLib

I'm using Mono to write a wrapper over a set of natively exposed commands.

The set is the same (commands and signature), however it is exposed through a DLL in Windows and a DyLib in Mac.

I was wondering if there was a way for me to create only one wrapper .NET/Mono DLL while having it still find the right library from which to import by itself.

If so, what would be the syntax? If not, what would be the compiler definitions that would separate the DllImport from 2 different OS on which I'd compile?

EDIT: Bonus points for a static lib (.a) instead of a dynamic lib (.dylib) for the Mac part, if that is even possible with Mono.

Upvotes: 2

Views: 2225

Answers (3)

konrad.kruczynski
konrad.kruczynski

Reputation: 47641

If you can give same names to both libraries, there would be no code changes required at all. At least it worked like that for me in Windows/Linux with native library written in C.

Upvotes: 2

jpobst
jpobst

Reputation: 9982

You will probably want to ship a dll map config file that tells Mono which library to load on each platform:

http://www.mono-project.com/Config_DllMap

Upvotes: 3

weismat
weismat

Reputation: 7411

I would use

#define MAC/WINDOWS

and

#if

inside your code. You use then -define WINDOWS or -define MAC when compiling so that the DLLs are called. So at least you will have one code base, alternatively you need to check for the environment, but this can get tricky easily.

Upvotes: -1

Related Questions