作者:nlyyan_613 | 来源:互联网 | 2023-09-10 19:49
Idontunderstandhowtorunc++codeinjavausingJNI.Ithinktheressomeerrorinthemakefile
I don't understand how to run c++ code in java using JNI. I think there's some error in the makefile, I think some lib are missing.
我不明白如何使用JNI在java中运行c ++代码。我认为makefile中有一些错误,我认为有些lib丢失了。
I have this code in java class:
我在java类中有这个代码:
private native void getCanny(long mat);
getCanny(mat.getNativeObjAddr());
and the Mat2Image.h generated:
和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
and this is the .cpp I've made:
这是我制作的.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);
}
and this is my makefile:
这是我的makefile:
# 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, $
but when I try to run the method I have this error:
但是当我尝试运行该方法时,我遇到了这个错误:
/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
I think the problem is the makefile, how can I edit it?
我认为问题是makefile,我该怎么编辑呢?
2 个解决方案