Mono DLL 打开适当的 Windows/Mac DLL/DyLib
我正在使用 Mono 编写一组本机公开命令的包装器。
该集是相同的(命令和签名),但是它通过 Windows 中的 DLL 和 Mac 中的 DyLib 公开。
我想知道是否有一种方法可以让我只创建一个包装器 .NET/Mono DLL,同时让它仍然找到正确的库来自行导入。
如果是这样,语法是什么?如果不是,那么将 DllImport 与我要编译的 2 个不同操作系统分开的编译器定义是什么?
编辑:对于 Mac 部分,使用静态库 (.a) 而不是动态库 (.dylib) 会得到加分,如果 Mono 也可以这样做的话。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想要发送一个 dll 映射配置文件,告诉 Mono 在每个平台上加载哪个库:
http:// /www.mono-project.com/Config_DllMap
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
如果您可以为两个库指定相同的名称,则根本不需要更改代码。至少它在 Windows/Linux 中对我来说是这样工作的,并且使用 C 编写的本机库。
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.
使用
and
我会在你的代码中 。
然后在编译时使用 -define WINDOWS 或 -define MAC 来调用 DLL。因此,至少您将拥有一个代码库,或者您需要检查环境,但这很容易变得棘手。
I would use
and
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.