Ask Your Question

Revision history [back]

c++ code of opencv project , run by java jni

Hi i have c++ code of opencv project , i will run this code by java jni my os is ubuntu , i create .so file by c++ code and try to run by java , but show this error :

main.so: undefined symbol: _ZN2cv6imreadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi

my c++ code :

include <iostream>

include "jni.h"

include "OpencvCpp.h"

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 opencv.hpp="">

include <stdio.h>

include <string.h>

using namespace cv; using namespace std;

JNIEXPORT jfloat JNICALL Java_OpencvCpp_myFirsttest (JNIEnv *, jobject){

//int main() {

Mat img, img2;

string filename = "/home/mohsen/Desktop/1.jpg";
img = imread(filename);
float m;
for (int i = 0; i < 96; ++i) {
    for (int j = 0; j < 96; ++j) {
        m = m + img.at<uchar>(i, j);
    }

}
cout << m;
return m;

}

my java.h code : /* DO NOT EDIT THIS FILE - it is machine generated */

include "jni.h"

/* Header for class OpencvCpp */

ifndef _Included_OpencvCpp

define _Included_OpencvCpp

ifdef __cplusplus

extern "C" {

endif

/* * Class: OpencvCpp * Method: myFirsttest * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_OpencvCpp_myFirsttest (JNIEnv *, jobject);

ifdef __cplusplus

}

endif

endif

my java code : public class Main {

static {
    System.load("/home/mohsen/IdeaProjects/DllTest/src/main.so");
}

public static void main(String[] args) {

    System.out.println(new OpencvCpp().myFirsttest());

}

}

please help me!

click to hide/show revision 2
None

updated 2019-04-17 01:36:29 -0600

berak gravatar image

c++ code of opencv project , run by java jni

Hi i have c++ code of opencv project , i will run this code by java jni my os is ubuntu , i create .so file by c++ code and try to run by java , but show this error :

main.so: undefined symbol: _ZN2cv6imreadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi

my c++ code :

include <iostream>

include "jni.h"

include "OpencvCpp.h"

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 opencv.hpp="">

include <stdio.h>

include <string.h>

#include <iostream>
#include "jni.h"
#include "OpencvCpp.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <string.h>

using namespace cv;
using namespace std;

std; JNIEXPORT jfloat JNICALL Java_OpencvCpp_myFirsttest (JNIEnv *, jobject){

jobject){ //int main() {

{
Mat img, img2;
 string filename = "/home/mohsen/Desktop/1.jpg";
 img = imread(filename);
 float m;
 for (int i = 0; i < 96; ++i) {
  for (int j = 0; j < 96; ++j) {
 m = m + img.at<uchar>(i, j);
}
}
 }
}
cout << m;
 return m;

}

} my java.h code : /* DO NOT EDIT THIS FILE - it is machine generated */

include "jni.h"

*/ #include "jni.h" /* Header for class OpencvCpp */

ifndef _Included_OpencvCpp

define _Included_OpencvCpp

ifdef __cplusplus

*/ #ifndef _Included_OpencvCpp #define _Included_OpencvCpp #ifdef __cplusplus extern "C" {

endif

{ #endif /* * Class: OpencvCpp * Method: myFirsttest * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_OpencvCpp_myFirsttest (JNIEnv *, jobject);

ifdef __cplusplus

}

endif

endif

jobject); #ifdef __cplusplus } #endif #endif my java code : public class Main {

{
static {
 System.load("/home/mohsen/IdeaProjects/DllTest/src/main.so");
}
 }
public static void main(String[] args) {
 System.out.println(new OpencvCpp().myFirsttest());
 }
}

}

please help me!