为树莓派编译 JD2XX
Posted
技术标签:
【中文标题】为树莓派编译 JD2XX【英文标题】:Compiling JD2XX for Raspberry Pi 【发布时间】:2017-10-29 20:03:00 【问题描述】:对于 Openhab2,有一个名为 RFXCOM 的绑定插件。然而问题是这个附加组件使用了与 Raspberry Pi 的 ARM 架构不兼容的 JD2XX。
我找到了一个 Github 存储库,其中包含可用于编译 *.so 文件的源代码:https://github.com/0x6a77/JD2XX
对 Makefile 稍作改动以使用正确的 Java 路径(zulu-8-armhf-embedded 而不是 (oracle-7)。
运行sudo make jni
创建一个*.so
文件,我将其复制到/usr/lib
(在java 库路径中)。但是我仍然收到 Raspberry Pi 无法打开共享库的错误,因为它是 32 位的。如何使用 Github 存储库提供的源代码编译适用于 ARM 的共享库。
错误信息:
java.lang.UnsatisfiedLinkError:
/var/lib/openhab2/tmp/libjd2xx5892592723514582617.so:
/var/lib/openhab2/tmp/libjd2xx5892592723514582617.so: cannot open shared object file:
No such file or directory (Possible cause: can't load IA 32-bit .so on a ARM-bit platform)
树莓派全新安装了Openh***。
Github 上的问题链接:https://github.com/openhab/openhab2-addons/issues/2316#issuecomment-304795652
编辑:
11:00:52.291 [ERROR] [rnal.discovery.RFXComBridgeDiscovery] - Error occurred during discovery
java.io.IOException: device not found (2)
at jd2xx.JD2XX.listDevices(Native Method)
at jd2xx.JD2XX.listDevicesByDescription(JD2XX.java:785)
at org.openhab.binding.rfxcom.internal.discovery.RFXComBridgeDiscovery.discoverRfxcom(RFXComBridgeDiscovery.java:89)
at org.openhab.binding.rfxcom.internal.discovery.RFXComBridgeDiscovery.startScan(RFXComBridgeDiscovery.java:66)
at org.eclipse.smarthome.config.discovery.AbstractDiscoveryService.startScan(AbstractDiscoveryService.java:199)
at org.eclipse.smarthome.config.discovery.internal.DiscoveryServiceRegistryImpl.startScan(DiscoveryServiceRegistryImpl.java:382)
at org.eclipse.smarthome.config.discovery.internal.DiscoveryServiceRegistryImpl.startScans(DiscoveryServiceRegistryImpl.java:358)
at org.eclipse.smarthome.config.discovery.internal.DiscoveryServiceRegistryImpl.startScan(DiscoveryServiceRegistryImpl.java:216)
at org.eclipse.smarthome.io.rest.core.discovery.DiscoveryResource.scan(DiscoveryResource.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_121]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)[157:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)[157:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)[157:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)[157:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)[157:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)[157:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)[158:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)[155:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)[155:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)[155:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)[155:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)[155:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76)[10:com.eclipsesource.jaxrs.publisher:5.3.1.201602281253]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[81:org.eclipse.jetty.servlet:9.2.19.v20160908]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[81:org.eclipse.jetty.servlet:9.2.19.v20160908]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[172:org.ops4j.pax.web.pax-web-jetty:4.3.0]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[79:org.eclipse.jetty.security:9.2.19.v20160908]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[172:org.ops4j.pax.web.pax-web-jetty:4.3.0]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[81:org.eclipse.jetty.servlet:9.2.19.v20160908]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[172:org.ops4j.pax.web.pax-web-jetty:4.3.0]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.Server.handle(Server.java:499)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[80:org.eclipse.jetty.server:9.2.19.v20160908]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[72:org.eclipse.jetty.io:9.2.19.v20160908]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[83:org.eclipse.jetty.util:9.2.19.v20160908]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[83:org.eclipse.jetty.util:9.2.19.v20160908]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
11:01:02.868 [WARN ] [e.sshd.server.channel.ChannelSession] - Unknown pty opcode value: 42
【问题讨论】:
你的文件名是 libjd2xx5892592723514582617.so 吗?我可以在 Makefile 中看到共享库 libjd2xx.so 的文件名。告诉我如果你在测试目录中使用 TestListener.sh 会发生什么?我认为这是 LD_LIBRARY_PATH 或 java.library.path 问题。 共享库被称为 libjd2xx.so 只有在 openhab2 复制后它才会得到一些数字后缀。我将它复制到 /usr/lib/ 这是路径和 chmod 755 以便能够读取它。你是什么意思TestListener? 好吧,不要介意github.com/0x6a77/JD2XX/tree/master/jd2xx/test下的TestListener.sh。你可以试试这个脚本吗? java -Xcheck:jni -Djava.library.path="你的库路径在哪里" -cp "到/jd2xx.jar:."测试监听器 【参考方案1】:在 JD2XX.java 文件中,您可以看到如何加载 dll 或其他类型的库的机制,具体取决于操作系统。
static
String dataModel = System.getProperty("sun.arch.data.model");
String osName = System.getProperty("os.name").toLowerCase();;
StringBuilder lib = new StringBuilder("/jni/");
if (osName.contains("win"))
lib.append("win/");
else if (osName.contains("linux"))
lib.append("linux/");
else if (osName.contains("mac"))
lib.append("mac/");
else
throw new UnsatisfiedLinkError("Loading JD2XX JNI: Unsupported operating system ("+osName+")");
if (dataModel.equals("32"))
lib.append("x86_32/");
else if (dataModel.equals("64"))
lib.append("x86_64/");
else
throw new UnsatisfiedLinkError("Loading JD2XX JNI: Unknown runtime data model ("+dataModel+")");
if (osName.contains("win"))
lib.append("jd2xx.dll");
else if (osName.contains("linux"))
lib.append("libjd2xx.so");
else if (osName.contains("mac"))
lib.append("libjd2xx.jnilib");
try
NativeUtils.loadLibraryFromJar(lib.toString());
catch (IOException e)
throw new UnsatisfiedLinkError(e.getMessage());
NativeUtils 的 loadLibraryFromJar 方法创建临时目录并将操作系统的正确库复制到临时目录,然后最终调用 System.load 方法。 所以,如果可能的话,我认为你应该把这部分源代码修改成如下代码。
static
System.load("/var/lib/openhab2/tmp/libjd2xx5892592723514582617.so");
或
static
System.load("/usr/lib/libjd2xx5892592723514582617.so");
有几种方法可以使这项工作重新设置“java.library.path”顺序以首先指示 /usr/lib 目录,然后使用下面的代码。
或者您可以将库名称 libjd2xx5892592723514582617.so 重命名为 /usr/lib 中的 libjd2xx.so,该文件通常位于“LD_LIBRARY_PATH”变量中。
那么,可以使用我们在JD2XX.java中的代码来代替,
static
System.loadLibrary("jd2xx");
我认为它有效..
【讨论】:
您对错误的来源是正确的。我重新编译了 *.so 和 *.jar 并解决了它,所以我将赏金给你。但是我得到一个新的错误。尽管如此,你解决了这个问题,所以我会给你赏金。新错误在原始帖子中如果您还有时间 :-) 好的,提前谢谢你。我在github.com/openhab/openhab2-addons/issues/1312 找到了这篇文章。首先你必须按照pdf文件ftdichip.com/Support/Documents/AppNotes/…然后,如果指令不起作用,然后尝试获得usb挂载点755权限。须藤 chmod 777 /dev/ttyUSB0。你能告诉我这一切完成后发生了什么吗? 不,似乎两者都不起作用,完全相同的堆栈跟踪。卸载了两个驱动程序并修改了 ttyUSB0 设备。 我找到了本期的文章..github.com/openhab/openhab2-addons/issues/625.你读过 RobertOnGit 的 cmets 吗? 是的,但那没有使用发现组件,所以它否定了使用 JD2XX 的意义对吧?以上是关于为树莓派编译 JD2XX的主要内容,如果未能解决你的问题,请参考以下文章