简体   繁体   English

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

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

I have seen some Java projects using taucs.dll , TAUCS —a C library of sparse linear solvers, through JNI in Windows.我已经看到一些 Java 项目使用taucs.dllTAUCS——一个稀疏线性求解器的 C 库,通过 Windows 中的 JNI。 I guess I can achieve the same in Mac OS X by compiling TAUCS into something like libTaucs.jnilib .我想我可以通过将 TAUCS 编译成类似libTaucs.jnilib东西在 Mac OS X 中实现相同的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.我可以访问库的代码,但不知道如何将其编译成 DLL,更不用说 JNI 库了。 So far I can compile only to a static library.到目前为止,我只能编译为静态库。

Is there a way to convert a DLL to a JNI library for Mac?有没有办法将 DLL 转换为 Mac 的 JNI 库? 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?如果有人有经验,将静态库包装在动态库中是否可以与 JNI 一起使用,尤其是对于 TAUCS?

Finally Microsoft released .NET Core which is completely platform independent.最后,微软发布了完全独立于平台的.NET Core When you build a DLL using .NET Core framework you can run the file with following command.当您使用 .NET Core 框架构建 DLL 时,您可以使用以下命令运行该文件。

dotnet yourapp.dll

Also, now .NET applications can be developed on Mac or Linux machine using the lightweight IDE Visual Studio Code and Visual Studio for Mac IDE has been released where Mono on MacOS X is integrated.此外,现在可以使用轻量级 IDE Visual Studio CodeVisual Studio for Mac IDE 在 Mac 或 Linux 机器上开发 .NET 应用程序,其中集成了 MacOS X上的Mono

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. DLL(动态链接库)是共享库的 Windows 版本。 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).您不能只在 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.您不需要尝试在 Mac OS 上使用 Windows DLL,而是需要找到您尝试使用的本机库的 Mac OS 特定版本。 Or if you have the source code, compile it into a Mac OS-native shared library.或者,如果您有源代码,请将其编译为 Mac OS 本地共享库。 Shared libraries on Mac OS X have the extension .so (instead of .dll), which stands for "shared object". Mac OS X 上的共享库的扩展名为 .so(而不是 .dll),它代表“共享对象”。
Loading them using just Java is not possible.仅使用 Java 加载它们是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM