UnsatisfiedLinkError JNI [英] UnsatisfiedLinkError JNI

查看:29
本文介绍了UnsatisfiedLinkError JNI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旧的 win32 项目无法在新的 vista 64 位机器上正确编译.我不使用 64 位 java.

An old win32 project does not compile correctly on new vista 64bit machine. I do not use 64-bit java.

package org.denkweise.coloredconsole;
public final class Console{
    static native void setColor(byte fg, byte bg);
}

转到 ColoredConsole32.h:

goes to ColoredConsole32.h:

#include <jni.h>
JNIEXPORT void __cdecl Java_org_denkweise_coloredconsole_Console_setColor(JNIEnv *, jobject, jbyte, jbyte);

转到 ColoredConsole32.cpp:

goes to ColoredConsole32.cpp:

#include "ColoredConsole32.h"
#include <windows.h>
JNIEXPORT void __cdecl Java_org_denkweise_coloredconsole_Console_setColor(JNIEnv * env, jobject ob, jbyte fg, jbyte bg) {
    /*stuff*/
}

并通过mingw编译成功

and compile successfully via mingw

g++ -D_JNI_IMPLEMENTATION_ -enable-stdcall-fixup -Wl,--kill-at ColoredConsole32.h -Ic:jdk1.6.0_26include -Ic:jdk1.6.0_26includewin32 -shared -o ColoredConsole.dll

System.loadLibrary 很好用,但是 setColor 会抛出一个

System.loadLibrary works great, but setColor throws an

java.lang.UnsatisfiedLinkError: org.denkweise.coloredconsole.Console.setColor(BB)V

有什么建议吗?

推荐答案

好吧,是我弄错了:

java 方法是静态的,但我的 c 方法的第二个参数是 jobject 而不是 jclass.

the java-method was static, but the 2nd param of my c-method was jobject instead of jclass.

使方法非静态解决了我的问题.

make the method unstatic solves my problem.

问候

这篇关于UnsatisfiedLinkError JNI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆