Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java DLL链接错误_Java_Dll_Linker_Usb_Libusb - Fatal编程技术网

Java DLL链接错误

Java DLL链接错误,java,dll,linker,usb,libusb,Java,Dll,Linker,Usb,Libusb,我正在使用libusb-- 然而,我得到: 线程“main”中出现异常 java.lang.UnsatifiedLink错误: USBManager.usb_init()V 尝试System.loadLibrary(“usb”)或者找不到usb.dll,请使用缩写路径而不是System.loadLibrary()尝试System.load(),以验证这一点 另一个问题可能是,libusb依赖于其他dll。用于查看libusb引用了哪些DLL 另一个问题可能是,DLL没有导出具有相应签名的函数。D

我正在使用libusb--

然而,我得到:

线程“main”中出现异常 java.lang.UnsatifiedLink错误: USBManager.usb_init()V


尝试
System.loadLibrary(“usb”)

或者找不到usb.dll,请使用缩写路径而不是System.loadLibrary()尝试System.load(),以验证这一点

另一个问题可能是,libusb依赖于其他dll。用于查看libusb引用了哪些DLL


另一个问题可能是,DLL没有导出具有相应签名的函数。DLL中应该有一个USBManager_usb_init()函数。使用
javah
创建正确的签名。

您不能只使用公共本机usb_init();然后像这样加载一个本机库,JNI不是这样实现的

您可以使用javah创建一个.h文件,该文件可用于创建实现类中特定本机函数的库

javac USBManager
创建一个与javah一起使用的类文件:

javah USBManager
这将在该位置生成一个名为“USBManager.h”的文件,该文件指定要在实现相关本机函数的.so/.dll中实现的函数

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class USBManager */

#ifndef _Included_USBManager
#define _Included_USBManager
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     USBManager
 * Method:    usb_init
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_USBManager_usb_1init
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

上面有一个非常好的简单示例,但是还有很多其他示例。

有一个已经编写好的示例。为什么不试试呢?

JNI非常简单,JNI访问的任何函数都需要针对类编写的本机包装函数。工具javah生成一个包含所需包装的头文件


要访问本机函数,请使用简单的方法

这是win,不是linux。在linux上,名为“libabc.so”的共享库由“abc”引用,而在win上,“libabc.dll”由“libabc.win”引用?你是说窗户?啊,对不起,不支持遗留系统:)Coola,我不知道库中有java包装器。这使事情变得很好,易于使用
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class USBManager */

#ifndef _Included_USBManager
#define _Included_USBManager
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     USBManager
 * Method:    usb_init
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_USBManager_usb_1init
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif
JNIEXPORT void JNICALL Java_USBManager_usb_1init (JNIEnv *, jobject) {
    usb_init();
}