将 .so 文件转换为 .jnilib 文件

发布于 2024-08-06 19:06:08 字数 474 浏览 3 评论 0原文

我有一个以 ELF 格式为 Linux 编译的 .so 库,该库正在由 Java 程序使用。我正在尝试将此应用程序移植到 Mac OS X,并发现 OS X 对这些文件使用不同的扩展名 .jnilib。我已经弄清楚如何设置 PATH 以便它正确找到文件。但是,OS X Java 无法加载 .so 文件(因为它需要其他扩展名)。

如果我将文件扩展名从 .so 更改为 .jnilib,JVM 可以找到这些文件,但无法读取它们(因为它们编译不正确)。

有没有办法,无论是在 Linux 系统还是在 Mac OS X 中,没有源代码,将这些 .so 文件转换为 .jnilib?我怀疑这是不可能的,但 Stack Overflow 还没有让我失望——而且我不会将“这不可能”算作失败。

I've got a .so library compiled for Linux under the ELF format, which is being used by a Java program. I'm trying to port this application to Mac OS X, and have discovered that OS X uses a different extension for these files, .jnilib. I've already figured out how to set up the PATH so that it correctly finds the files. However, OS X Java cannot load the .so files (because it expects the other extension).

If I change the file extension from .so to .jnilib, the JVM can find the files but can't read them (since they've been compiled incorrectly).

Is there any way, either in a Linux system or in Mac OS X, without the source code, to convert these .so files to .jnilib? I suspect that this is not possible, but Stack Overflow hasn't failed me yet - and I wouldn't count "it's not possible" as failure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离 2024-08-13 19:06:08

您是否尝试在 Mac OS X 上使用适用于 Linux 的本机库?不,那是行不通的。

您需要获取 Mac 版本的本机库,并将其重命名为 jnilib(如果它还没有该后缀)。

这是 JVM 字节码和本机代码之间的主要区别。本机代码是非常特定于平台的。我们甚至有针对不同 Linux 风格的多个版本的 JNI 库。

由于 Mac 和 Linux 都使用相同的 CPU 并且它们都是基于 Unix 的,所以我不会说这是不可能的,尽管它非常接近。

Are you trying to use a native library for Linux on Mac OS X? No. That's not going to work.

You need get a Mac version of the native library and rename it to jnilib if it doesn't have that suffix already.

That's the main difference between JVM byte code and native code. Native code is very platform specific. We even have multiple versions of JNI libraries for different linux flavors.

Since Mac and Linux all uses the same CPU and they are all Unix-based, I wouldn't say it's impossible even though it's pretty close to that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文