gpt4 book ai didi

java - 动态链接库和Java

转载 作者:行者123 更新时间:2023-12-01 05:06:19 24 4
gpt4 key购买 nike

我用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++ 函数中,并且它有效。谢谢。

最佳答案

如果集成到 makefile 中,使用 javah 实用程序可能会有所帮助,以确保双方(客户端/服务器)始终假定接口(interface)。

关于java - 动态链接库和Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12612891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com