热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为jniapp添加lib到makefile-Addlibtomakefileforjniapp

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 个解决方案

#1


0  

It looks like your code is using symbols that are not linked.

看起来您的代码使用的是未链接的符号。

I suggest to link your shared lib with opencv ?

我建议将您的共享库与opencv链接?

If you want to look at sample code where shared library is used from JNI, take a look here:

如果您想查看从JNI使用共享库的示例代码,请查看此处:

https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo023

In your case, it looks like opencv library is not on LD_LIBRARY_PATH.

在您的情况下,看起来opencv库不在LD_LIBRARY_PATH上。

#2


0  

I solved by modifying the makefile:

我通过修改makefile解决了:

i change

libMat.so : libMat.o
    g++ $(CFLAGS) -W -shared -o $@ $<

with

libMat.so : libMat.o
    g++ $(CFLAGS) -W -shared -o $@ $<-lopencv_imgproc

this is the final 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, $

推荐阅读
  • 本文概述了JNI的原理以及常用方法。JNI提供了一种Java字节码调用C/C++的解决方案,但引用类型不能直接在Native层使用,需要进行类型转化。多维数组(包括二维数组)都是引用类型,需要使用jobjectArray类型来存取其值。此外,由于Java支持函数重载,根据函数名无法找到对应的JNI函数,因此介绍了JNI函数签名信息的解决方案。 ... [详细]
  • 在CentOS/RHEL 7/6,Fedora 27/26/25上安装JAVA 9的步骤和方法
    本文介绍了在CentOS/RHEL 7/6,Fedora 27/26/25上安装JAVA 9的详细步骤和方法。首先需要下载最新的Java SE Development Kit 9发行版,然后按照给出的Shell命令行方式进行安装。详细的步骤和方法请参考正文内容。 ... [详细]
  • Java在运行已编译完成的类时,是通过java虚拟机来装载和执行的,java虚拟机通过操作系统命令JAVA_HOMEbinjava–option来启 ... [详细]
  • 32位ubuntu编译android studio,32位Ubuntu编译Android 4.0.4问题
    问题一:在32位Ubuntu12.04上编译Android4.0.4源码时,出现了关于emulator的错误,关键是其Makefile里的 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • 本文介绍了深入浅出Linux设备驱动编程的重要性,以及两种加载和删除Linux内核模块的方法。通过一个内核模块的例子,展示了模块的编译和加载过程,并讨论了模块对内核大小的控制。深入理解Linux设备驱动编程对于开发者来说非常重要。 ... [详细]
  • 本文讨论了在VMWARE5.1的虚拟服务器Windows Server 2008R2上安装oracle 10g客户端时出现的问题,并提供了解决方法。错误日志显示了异常访问违例,通过分析日志中的问题帧,找到了解决问题的线索。文章详细介绍了解决方法,帮助读者顺利安装oracle 10g客户端。 ... [详细]
  • 本文介绍了NetCore WebAPI开发的探索过程,包括新建项目、运行接口获取数据、跨平台部署等。同时还提供了客户端访问代码示例,包括Post函数、服务器post地址、api参数等。详细讲解了部署模式选择、框架依赖和独立部署的区别,以及在Windows和Linux平台上的部署方法。 ... [详细]
  • Mono为何能跨平台
    概念JIT编译(JITcompilation),运行时需要代码时,将Microsoft中间语言(MSIL)转换为机器码的编译。CLR(CommonLa ... [详细]
  • 初识java关于JDK、JRE、JVM 了解一下 ... [详细]
  • 近来有一个需求,是需要在androidjava基础库中插入一些log信息,完成这个工作需要的前置条件有编译好的android源码具体android源码如何编译,这 ... [详细]
  • Linux 程序设计学习笔记----动手编写makefile文件
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 编写一个简单的内核驱动模块时报错 “/lib/modules/3.13.032generic/bulid: 没有那个文件或目录。 停止。”...
    编写一个简单的内核驱动模块1staticinthello_init()2{3printk(“hello,Iaminkernelnow\n”);4return0;5}6voidadd ... [详细]
author-avatar
nlyyan_613
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有