CPP菜鸟在这里。我正在尝试从我的 Java 应用程序调用库函数。在我的 java 类中匹配 C 函数的数据类型时需要帮助
C 函数签名
#define I_REAL double
int myfunction(int size,
I_REAL const *const *inputs,
I_REAL const *options,
I_REAL *const *outputs);
我的 java 本地方法签名(这可能不正确,我不确定const *const *inputs
在 java 中将如何翻译)
public static native int myfunction(int size,
final double[][] inputs,
final double[] options,
final double[][] outputs);
然后我使用生成头文件 javac Myclass.java -h .
然后我实现了我的 cpp 代码 -
JNIEXPORT jint JNICALL Java_com_raj_myfunction
(JNIEnv *, jclass, jint, jobjectArray, jdoubleArray, jobjectArray)
{
// something useful here
}
我收到运行时错误 - java.lang.NoSuchMethodError: com.raj.Myclass.myfunction(I[D[D[D)I
我在想我的 java 本机方法签名有问题。我必须匹配 C 函数签名,任何帮助表示赞赏。
在这里改变两件事:
reinterpret_cast
所以在你的 jni 函数调用中你必须做 -reinterpret_cast<I_REAL const *const*>(&inputs)
你在那里调用你的 C 函数。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句