#include "testdll.h"
int i = 0;
JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv * env, jclass jc)
{
return i;
}
JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *env, jclass jc, jint j)
{
i = j;
}
void main()
{ }
改成这样试试
int i = 0;
JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv * env, jclass jc)
{
return i;
}
JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *env, jclass jc, jint j)
{
i = j;
}
void main()
{ }
改成这样试试
我想知道你的C++头文件是怎样生成的?
JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv * env, jclass jc)
----
jclass哪来的?
一般是jobject呀
我想看看javah DllTest生成的头文件的内容
#include <jni.h>
/* Header for class dllTest_DllTest */#ifndef _Included_dllTest_DllTest
#define _Included_dllTest_DllTest
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: dllTest_DllTest
* Method: get
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_dllTest_DllTest_get
(JNIEnv *, jclass);/*
* Class: dllTest_DllTest
* Method: set
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_dllTest_DllTest_set
(JNIEnv *, jclass, jint);#ifdef __cplusplus
}
#endif
#endif
我写的都是生成jobject呀
那我也不知道了
按道理头文件和源文件应该和java的那个类的名字是一样的啊
这样生成的DLL看看能用不
有问题多讨论吧,我QQ:66060828
.h文件是javah生成的,注释里说不要修改。不过我改着试了一下,不行;把cpp文件改成
#include "dllTest_TestDll.h"
int i = 0;
extern "C" JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass)
{
return i;
}
extern "C" JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint j)
{
i = j;
}
也不行,都是同样错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: set
at dllTest.TestDll.set(Native Method)
at dllTest.TestDll.main(TestDll.java:14)
set是java里native的方法。
我没有说明白,不是改。h文件中的,而是修改方法实现文件(即.cpp)文件中的外部方法申明!