Добавьте библиотеку в make-файл для приложения jni.C++

Программы на C++. Форум разработчиков
Anonymous
Добавьте библиотеку в make-файл для приложения jni.

Сообщение Anonymous »

Я не понимаю, как запустить код C++ в Java с помощью JNI.
Я думаю, что в make-файле какая-то ошибка, мне кажется, что некоторые библиотеки отсутствуют.

У меня есть этот код в классе Java:

Код: Выделить всё

private native void getCanny(long mat);
getCanny(mat.getNativeObjAddr());
и сгенерированный файл Mat2Image.h:

Код: Выделить всё

/* DO NOT EDIT THIS FILE - it is machine generated */
#include 
/* Header for class Mat2Image */

#ifndef _Included_Mat2Image
#define _Included_Mat2Image
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:     Mat2Image
* Method:    getCanny
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_Mat2Image_getCanny
(JNIEnv *, jobject, jlong);

#ifdef __cplusplus
}
#endif
#endif
а это созданный мною .cpp:

Код: Выделить всё

#include "Mat2Image.h"
#include 
#include 
#include 

JNIEXPORT void JNICALL Java_Mat2Image_getCanny
(JNIEnv * env, jobject obj, jlong matr){

cv::Mat* frame=(cv::Mat*)matr;
cv::cvtColor(*frame, *frame, CV_BGR2GRAY);
cv::GaussianBlur(*frame, *frame, cv::Size(7,7), 1.5, 1.5);
cv::Canny(*frame, *frame, 0, 30, 3);

}
а это мой make-файл:

Код: Выделить всё

# Define a variable for classpath
CLASS_PATH = ../bin

# Debug: -g3=compile with extra debugg infos. -ggdbg3=include things like macro defenitions. -O0=turn off optimizations.
DEBUGFLAGS = -g3 -ggdb3 -O0
CFLAGS = $(DEBUGFLAGS)

# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)

all : libMat.so

# $@ matches the target, $< matches the first dependancy
libMat.so : libMat.o
g++ $(CFLAGS) -W -shared -o $@ $<

# $@ matches the target, $< matches the first dependancy
libMat.o : Mat2Image.cpp Mat2Image.h
g++ $(CFLAGS) -fPIC -I/usr/lib/jvm/jdk1.8.0_111/include -I/usr/lib/jvm/jdk1.8.0_111/include/linux -c $< -o $@

# $* matches the target filename without the extension
# manually this would be: javah -classpath ../bin HelloJNI
HelloJNI.h : Mat2Image.class
javah -classpath $(CLASS_PATH) $*

clean :
rm -f Mat2Image.h libMat.o libMat.so
но когда я пытаюсь запустить метод, у меня возникает ошибка:

Код: Выделить всё

/usr/lib/jvm/jdk1.8.0_111/bin/java: symbol lookup error: /home/buzzo/Downloads/helloJni-master/jni/libMat.so: undefined symbol: _ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii
Я думаю, проблема в make-файле, как его отредактировать?

Подробнее здесь: https://stackoverflow.com/questions/438 ... or-jni-app

Вернуться в «C++»