我正在爲工作編寫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」,它沒有效果。我認爲這可能是我的問題,但我不確定。