仕事用にlibvpxのビデオエンコーダラッパーを書いていますが、Javaでこれらの関数を呼び出そうとすると、java.lang.UnsatisfiedLinkErrorが発生します。
これが私の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
私の知る限り、必要なものはすべて適切にエクスポートしました。私はMicrosoftVisualC(2010 Express)を使用しており、jvm.libおよびjawt.libに対してリンクしており、MFCおよびALTライブラリに対して静的にリンクしています。私は何かを逃しましたか?
DLLの構築中に言及する必要がありますが、次の出力が得られます。
1>ライブラリC:\ Users \ Alexander \ youeye-rnd \ java-rnd \ libvpx-youeye \ msvc \ libvpx_ye \ Debug \ libvpx_ye.libとオブジェクトC:\ Users \ Alexander \ youeye-rnd \ java-rnd\libvpxを作成しています-youeye \ msvc \ libvpx_ye \ Debug \ libvpx_ye.exp
1>リンク:警告LNK4098:defaultlib'LIBCMT'は他のライブラリの使用と競合します。/NODEFAULTLIB:library 1> libvpx_ye.vcxproj-> C:\ Users \ Alexander \ youeye-rnd \ java-rnd \ libvpx-youeye \ msvc \ libvpx_ye \ Debug\libvpx_ye.dllを使用します
「特定のデフォルトライブラリを無視する」(「リンカー」>「入力」の下)を「/ NODEFAULTLIB:libcmt」に設定しようとしましたが、効果がありませんでした。これが私の問題かもしれないと思いますが、絶対にわかりません。