的UnsatisfiedLinkError JNIUnsatisfiedLinkError、JNI

2023-09-09 21:16:48 作者:≮孤僻者的高冷方式≯

这是旧的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_26\include -Ic:\jdk1.6.0_26\include\win32 -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

任何建议吗?

any sugestions?

推荐答案

好了,是我的错:

Java的方法是静态的,但我的C-方法的第二个参数是不是JCLASS jobject。

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

请unstatic解决我的问题的方法。

make the method unstatic solves my problem.

问候