I made .c file to use in JNI. .java, .h, .c and compiled nicely:D
My environment is Windows 7 64 bits.
However, the problem that I am facing is about another external library.
I received a library that consists of one header file and one lib file.
What I did is below.
I. copy XXX.h and XXX.lib into the same physical directory where original JNI files are.
in my case: C:\Users\JY\worspace\Test\org\owls\src\jni\
and now I have these files in there:
Original files:
IIS.java
IIS.class
org_owls_jni_IIS.h
IIS.c
Newly added:
II. added the directive #include "XXX.h"
to the .c file. So IIS.c now looks like this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "org_owls_jni_IIS.h"
#include "XXX.h"
JNIEXPORT jint JNICALL Java_org_owls_jni_IIS_doIIS
(JNIEnv* env, jobject jobj, jstring jtarget, jstring jdest, jstring jimage){
jboolean iscp;
int video_len = 0;
char* a = "aaa";
const char* ctarget = (*env)->GetStringUTFChars(env, jtarget, &iscp);
const char* cdest = (*env)->GetStringUTFChars(env, jdest, &iscp);
const char* cimage = (*env)->GetStringUTFChars(env, jimage, &iscp);
fprintf(stderr, "VIDEO [ %s ] THUMBNAIL [ %s ]\n", ctarget, cdest);
sprintf(tmp, "C : %s\t%s", ctarget, cdest);
fprintf(stderr, "%s\n", tmp);
Call_XXX(a);
(*env)->ReleaseStringUTFChars(env, jtarget, ctarget);
(*env)->ReleaseStringUTFChars(env, jdest, cdest);
(*env)->ReleaseStringUTFChars(env, jimage, cimage);
return (jint)video_len;
}
Call_XXX()
is defined in XXX.h and it receives an argument type of char *
.
III. compiling with the cl
command via VS2012 x64 Native Tools Command Prompt.
Command line is:
cl IIS.c -Feiis.dll -LD -MD
cl IIS.c -Feiis.dll -LD -MD -link XXX.lib
IV. Now the problem comes. Normally, If adding a header file succeeds, there's no problem with calling a function which is declared in that header. But in my case, there's an error. Symptoms are below.
error messages are :
IIS.c
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:iis.dll
/dll
/implib:iis.lib
IIS.obj
iis.lib 라이브러리 및 iis.exp 개체를 생성하고 있습니다.
IIS.obj : error LNK2019:Call_XXX 외부 기호(참조 위치: Java_org_owls_jni_IIS_doIIS 함수)에서 확인하지 못했습니다.
iis.dll : fatal error LNK1120:
I erased some messages, because those are not in English. But since I left the error codes, I guess that there is no problem with recognizing causes and the situation.