我在 C++ 中创建了一个 dll,并在 java 中编写了这个类:
public class VolumeControl {
public native float GetVolume();
public native void SetVolume(float val);
public native void VolumeUp();
public native void VolumeDown();
public native void Mute();
static {
System.load("some_path/VolumeControl.dll");
}
}
如果我从这个文件中调用函数,它工作得很好,但是当我试图这样做时:
public class Server {
public static void main(String[] args) {
VolumeControl ctrl = new VolumeControl();
ctrl.Mute();
}
}
我明白了:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
RemoteControl.VolumeControl.Mute()V
当然,这两个类都在同一个包中。我该如何解决?谢谢。
Update1:好的问题是,我将这些类添加到包中。当我将它们移动到默认包时,一切正常。但是现在如果我想将此 dll 与不同的包一起使用,我需要重新构建它。
Update2:实际上我根本无法将它添加到包中,当我尝试时:#javah VolumeControl,我得到错误:
Could not find class file for 'VolumeControl'.
Update3:我手动将包的名称添加到 C++ 函数中,它可以工作。谢谢。