Reputation: 23
I'm working in an Android project with c++ files (NDK) but i have faced a problem native method not found , when i add the extern "C" { } i got new problem which is declaration of c function '..' conflicts with .h previous declaration here is my code
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_marwen_parojet_ocr_2_PostPhot */
#ifndef _Included_com_marwen_parojet_ocr_2_PostPhot
#define _Included_com_marwen_parojet_ocr_2_PostPhot
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_marwen_parojet_ocr_2_PostPhot
* Method: Traiter
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_com_marwen_parojet_1ocr_12_PostPhot_Traiter
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif
this traitement_jni.h and the .cpp file is
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>
#include "opencv2/ml/ml.hpp"
#include <android/log.h>
#include <jni.h>
#include "traitement_jni.h"
#include <stdlib.h>
extern "C" {
JNIEXPORT void JNICALL Java_com_marwen_parojet_1ocr_12_PostPhot_Traiter(JNIEnv* env, jobject,jstring path){
...
}
}
Upvotes: 0
Views: 621
Reputation: 153840
It seems you are passing a jclass
in the declaration but a jobject
in the definition. If these two types aren't aliases for the same type, this doensn't work: you cannot overload extern "C" functions.
header file:
extern "C" {
JNIEXPORT void JNICALL Java_com_marwen_parojet_1ocr_12_PostPhot_Traiter(
JNIEnv *,
jclass, // <---- here
jstring);
}
source file:
...
extern "C" {
JNIEXPORT void JNICALL Java_com_marwen_parojet_1ocr_12_PostPhot_Traiter(
JNIEnv* env,
jobject, // <---- here
jstring path){
...
}
}
Upvotes: 1