macos 如何在 Mac OS X 中使用带有 Java 的 Windows DLL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7901438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:32:45  来源:igfitidea点击:

How to use a Windows DLL with Java in Mac OS X?

javacmacosdlljava-native-interface

提问by puri

I have seen some Java projects using taucs.dll, TAUCS—a C library of sparse linear solvers, through JNI in Windows. I guess I can achieve the same in Mac OS X by compiling TAUCS into something like libTaucs.jnilib. I have access to the library's code but no idea how to compile it into a DLL, let alone a JNI library. So far I can compile only to a static library.

我已经使用看到了一些Java项目taucs.dllTAUCS在Windows -aÇ稀疏线性解算器库,通过JNI。我想我可以通过将 TAUCS 编译成类似libTaucs.jnilib. 我可以访问库的代码,但不知道如何将其编译成 DLL,更不用说 JNI 库了。到目前为止,我只能编译为静态库。

Is there a way to convert a DLL to a JNI library for Mac? If I have to compile the code, how to do so? Will wrapping a static library in a dynamic library work with JNI, especially for TAUCS if anyone has an experience?

有没有办法将 DLL 转换为 Mac 的 JNI 库?如果我必须编译代码,该怎么做?如果有人有经验,将静态库包装在动态库中是否可以与 JNI 一起使用,尤其是对于 TAUCS?

回答by Shahdat

Finally Microsoft released .NET Corewhich is completely platform independent. When you build a DLL using .NET Core framework you can run the file with following command.

最后,微软发布了完全独立于平台的.NET Core。当您使用 .NET Core 框架构建 DLL 时,您可以使用以下命令运行该文件。

dotnet yourapp.dll

Also, now .NET applications can be developed on Mac or Linux machine using the lightweight IDE Visual Studio Codeand Visual Studio for MacIDE has been released where Mono on MacOS Xis integrated.

此外,现在可以使用轻量级 IDE Visual Studio CodeVisual Studio for MacIDE在 Mac 或 Linux 机器上开发 .NET 应用程序,其中集成了 MacOS X上的Mono

回答by Sumit Singh

Many operating systems have the concept of shared libraries, but ofcourse the format etc. of such libraries is different on different operating systems.

很多操作系统都有共享库的概念,当然不同的操作系统这些库的格式等是不一样的。

DLLs (Dynamically Linked Libraries) are the Windows version of shared libraries. You cannot just use a DLL from a Windows machine on Mac OS, exactly like you cannot run a Windows application on Mac OS (or any other operating system).

DLL(动态链接库)是 Windows 版本的共享库。您不能只在 Mac OS 上使用 Windows 机器上的 DLL,就像您不能在 Mac OS(或任何其他操作系统)上运行 Windows 应用程序一样。

Instead of trying to use a Windows DLL on Mac OS, you need to find a Mac OS-specific version of the native library that you are trying to use. Or if you have the source code, compile it into a Mac OS-native shared library. Shared libraries on Mac OS X have the extension .so (instead of .dll), which stands for "shared object".
Loading them using just Java is not possible.

您不需要尝试在 Mac OS 上使用 Windows DLL,而是需要找到您尝试使用的本机库的 Mac OS 特定版本。或者,如果您有源代码,请将其编译为 Mac OS 本地共享库。Mac OS X 上的共享库的扩展名为 .so(而不是 .dll),它代表“共享对象”。
仅使用 Java 加载它们是不可能的。