我正在为工作编写libvpx的视频编码器封装,但在Java中,当我尝试调用这些函数时,得到java.lang.UnsatisfiedLinkError。Java/JNI/MSVC java.lang.UnsatisfiedLinkError我的DLL函数
这里是我的Java代码:
package default;
class YE_Vpx {
native int create_stream(String path, int w, int h, int fps);
native void finalize_stream(int streamid);
native void append_stream(int streamid, int[] pixels);
native void finalize_streams();
static {
System.loadLibrary("libvpx_ye"); // This loads the DLL just fine (windows 7), otherwise it would tell me it wasn't in the java.library.path
}
}
这里是我的C头(由JAVAH生成):
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class YE_Vpx */
#ifndef _Included_YE_Vpx
#define _Included_YE_Vpx
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: YE_Vpx
* Method: create_stream
* Signature: (Ljava/lang/String;III)I
*/
JNIEXPORT jint JNICALL Java_YE_1Vpx_create_1stream
(JNIEnv *, jobject, jstring, jint, jint, jint);
/*
* Class: YE_Vpx
* Method: finalize_stream
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_YE_1Vpx_finalize_1stream
(JNIEnv *, jobject, jint);
/*
* Class: YE_Vpx
* Method: append_stream
* Signature: (I[I)V
*/
JNIEXPORT void JNICALL Java_YE_1Vpx_append_1stream
(JNIEnv *, jobject, jint, jintArray);
/*
* Class: YE_Vpx
* Method: finalize_streams
* Signature:()V
*/
JNIEXPORT void JNICALL Java_YE_1Vpx_finalize_1streams
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
这里是我的C代码(引用我不其他文件牛逼想我可以在这里提出):
#include <jni.h>
#include <jni_md.h>
#include <sys/types.h>
#include "ye_vpx.h" // This is the javah generated header
#include "ye_vpx_c.h" // This is where most of the meat is, I can't actually post this file =/
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_YE_1Vpx_create_1stream(JNIEnv *env, jobject obj, jstring path, jint w, jint h, jint fps)
{
jboolean iscopy;
const jchar *m_path = (*env)->GetStringChars(env, path, &iscopy);
jint ret = ye_vpx_create_stream((const char *)m_path, w, h, fps);
(*env)->ReleaseStringChars(env, path, m_path);
return ret;
}
JNIEXPORT void JNICALL Java_YE_1Vpx_finalize_1stream(JNIEnv *env, jobject obj, jint streamid)
{
ye_vpx_finalize_stream(streamid);
}
JNIEXPORT void JNICALL Java_YE_1Vpx_append_1stream(JNIEnv *env, jobject obj, jint streamid, jintArray pixels)
{
jint *px = NULL;
int length = 0;
length = (*env)->GetArrayLength(env, pixels);
px = (jint *)calloc(length, sizeof(jint));
(*env)->GetIntArrayRegion(env, pixels, 0, length, px);
//px = (jint *)GetIntArrayElements(env, pixels, &iscopy);
ye_vpx_append_stream(streamid, px);
free(px);
}
JNIEXPORT void JNICALL Java_YE_1Vpx_finalize_1streams(JNIEnv *env, jobject obj)
{
ye_vpx_finalize_streams();
}
#ifdef __cplusplus
}
#endif
据我所知,我已经远销一切必要和适当的。我正在使用Microsoft Visual C(2010 Express),并且正在链接jvm.lib和jawt.lib,并且正在静态链接MFC和ALT库。我错过了什么吗?
同时建立我的DLL,我应该提,我得到下面的输出:
1>创建库C:\用户\亚历山大\ youeye-RND \ java的RND \ libvpx-youeye \ MSVC \ libvpx_ye \调试\ libvpx_ye.lib 和对象C:\用户\亚历山大\ youeye-RND \ java的RND \ libvpx-youeye \ MSVC \ libvpx_ye \调试\ libvpx_ye.exp
1> LINK:警告LNK4098:defaultlib' LIBCMT'与使用其他库相冲突;使用/ NODEFAULTLIB:库1> libvpx_ye.vcxproj - > C:\用户\亚历山大\ youeye-RND \ java的RND \ libvpx-youeye \ MSVC \ libvpx_ye \调试\ libvpx_ye.dll
我试图设置“忽略特定的默认库”(在链接器>输入下)到“/ NODEFAULTLIB:libcmt”,它没有效果。我认为这可能是我的问题,但我不确定。