如何在Linux中进行延迟/延迟加载?

编程入门 行业动态 更新时间:2024-10-26 15:29:41
本文介绍了如何在Linux中进行延迟/延迟加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Windows上运行得很好 - 应用程序加载我的插件(C ++,Qt),我的插件进行智能搜索以找到已安装的JRE,相应地设置库搜索路径,然后在JVM中调用一个函数强制在那时加载jvm.dll。 (上一个问题:如何部署混合C ++ / Java(JNI)应用程序?)

I got this working great on Windows -- application loads my plugin (C++, Qt), my plugin does a smart search to find an installed JRE, sets the library search path accordingly, and then calls a function in the JVM which forces the jvm.dll to be loaded at that point. (Previous question: How can I deploy a mixed C++/Java (JNI) application?)

现在我正试图让它在Linux上运行。从我读到的,延迟链接/加载是默认的,所以我认为它会工作....似乎不喜欢它。

Now I'm trying to get it working on Linux. From what I read, lazy linking/loading was the default, so I thought it would just work.... doesn't seem like it.

我想要避免 dlopen()和 dlsym(), LD_LIBRARY_PATH , ldconfig 等。这个想法是这个插件的用户不应该知道它是如何工作的,他们只是将plugin.so放在正确的位置,当它被加载时,该插件有智能找到JRE(或告诉用户安装JRE)。

I'd like to avoid dlopen() and dlsym(), LD_LIBRARY_PATH, ldconfig, etc. The idea is that users of this plugin shouldn't have to know how any of that works, they just put the plugin.so in the right place, and when it's loaded, the plugin has the smarts to find the JRE (or tell the user to install a JRE).

可以这样做吗?

编辑

为了清楚...加载插件时出现的错误: 无法加载库/home/dan/blah/blah/libMyPlugin.so:(libjawt.so:无法打开共享对象文件:没有这样的文件或目录)

Just to be clear... the error I get when the plugin is loaded: "Cannot load library /home/dan/blah/blah/libMyPlugin.so: (libjawt.so: cannot open shared object file: No such file or directory)"

编辑

如果重要......这需要适用于Ubuntu 10.10及更高版本,CentOS 5.4和OSX 10.6 +。

If it matters... this needs to work on Ubuntu 10.10 and up, on CentOS 5.4, and OSX 10.6+.

在Ubuntu 10.10上,我做了 apt-get install open jdk-6-jdk 然后为了让事情正确运行我必须

On Ubuntu 10.10, I did apt-get install openjdk-6-jdk and then to get things to run correctly I had to

export LD_LIBRARY_PATH= /usr/lib/jvm/java-6-openjdk/jre/lib/i386: /usr/lib/jvm/java-6-openjdk/jre/lib/i386/client: /usr/lib/jvm/java-6-openjdk/jre/lib/i386/xawt

(易读性的换行符)

但是如果有人安装了不同的JDK(例如,Sun),那么目录可能会有所不同(?)。

But if someone had a different JDK installed (e.g., Sun's) then the directories would probably differ (?).

推荐答案

你是如何在Windows上进行智能搜索的?在Linux中有几个正常的位置。

How did you conduct the smart search on windows? There are a couple of "normal" places to look in Linux.

很多时候,$ JAVA_HOME环境变量被设置为当前的JRE。

A lot of times the $JAVA_HOME environment variable is set to the current JRE.

我没有准备好访问您列出的所有系统,但在某些发行版上,您有一个符号链接/ usr / java / latest,它将指向最新安装的版本。

I don't have ready access to all of the systems you listed, but on some distros, you have a symlink /usr/java/latest which will point to the latest installed version.

一般情况下,如果安装了JRE,它可能位于/ usr / lib / jvm *,/ usr / java *,/ usr / lib / java之一*,或者可能是上述的lib64变种之一。

In general, if there's a JRE installed, it will probably be in one of /usr/lib/jvm*, /usr/java*, /usr/lib/java*, or possibly one of the lib64 varieties of the above.

当然,上述方法很可能会指向 a JRE。决定使用哪个可能会很棘手,但是如果你的代码不依赖于最新和最好的代码,它可能会没问题。

Of course, the above methods will most likely point you to a JRE. Deciding which to use might be tricky, but if your code doesn't rely on the latest and greatest, it will probably be okay.

我想作为询问你的一部分用户安装JRE如果找不到,你可以要求他们设置$ JAVA_HOME作为相当标准的做法。

I suppose as part of asking your user to install a JRE if one can't be found, you could ask them to set $JAVA_HOME as that's fairly standard practice.

我不知道是否确定因为部分问题源于* nix发行版的性质,所以它可以解决所有发行版的问题。但是,我可能还有一个额外的约定。

I don't know of a sure fire way for it to work on all distros, since part of the problem stems from the nature of *nix distributions. There may be an additional convention that I'm missing, however.

更多推荐

如何在Linux中进行延迟/延迟加载?

本文发布于:2023-11-14 10:37:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   如何在   Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!