Apr 10, 2015 11:28 AM
(This post was last modified: Apr 10, 2015 11:30 AM by Zy0n.)
I'm attempting to compile and create a shared library to use between the Java Native Interface and the OpenCV library. Ultimately I want to access and use the bagofwords class functions available in the default version of OpenCV, but not in the Java port which I am using. But for the moment I am just testing some simple functions to see if they work.
Here they are as follows:
And here is my cpp class.
I'm doing this on a Ubuntu VPS machine, using the gcc compiler I am running the following command:
This compiles the .so library successfully, but checking it i get several undefined reference errors as such:
Which leads me to beleive I am not referencing the libraries properly, but if that's the case what am i missing?
Here they are as follows:
PHP Code
<?php
class Bridge1 {
static {
System.loadLibrary("Bridge1");
}
public native int BridgeFunction();
public static void main(String[] args) {
Bridge1 b = new Bridge1();
b.BridgeFunction();
}
}
And here is my cpp class.
PHP Code
<?php
#include "Bridge1.h"
#include <string.h>
#include <cv.h>
#include "/var/opencv/opencv/modules/core/include/opencv2/core.hpp"
#include "/var/opencv/opencv/modules/highgui/include/opencv2/highgui.hpp"
JNIEXPORT jint JNICALL Java_Bridge1_BridgeFunction(JNIEnv *env, jobject obj) {
// IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
cv::Mat::eye(1,1,0);
return 1;
}
int main(){}
I'm doing this on a Ubuntu VPS machine, using the gcc compiler I am running the following command:
PHP Code
<?php
g++ -Wall -shared-libgcc -Im -o libBridge1.so Bridge1.cpp -fPIC
-I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include
-I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include/linux
-I/var/opencv/opencv/include
-I/var/opencv/opencv/include/opencv
-I/var/opencv/opencv/modules/core/include
-I/var/opencv/opencv/modules/imgproc/include
-I/var/opencv/opencv/modules/photo/include
-I/var/opencv/opencv/modules/objdetect/include
-I/var/opencv/opencv/modules/imgcodecs/include
-I/var/opencv/opencv/modules/videoio/include
-I/var/opencv/opencv/modules/highgui/include
-L/var/opencv/opencv/build/lib -lopencv_core249
-L/var/opencv/opencv/build/lib -lopencv_features2d
-L/var/opencv/opencv/build/lib -lopencv_imgproc
-I/var/opencv/opencv/build/lib
This compiles the .so library successfully, but checking it i get several undefined reference errors as such:
PHP Code
<?php
/tmp/ccSCYpYN.o: In function `Java_Bridge1_BridgeFunction':
Bridge1.cpp:(.text+0x33): undefined reference to `cv::Mat::eye(int, int, int)'
/tmp/ccSCYpYN.o: In function `cv::Mat::~Mat()':
Bridge1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccSCYpYN.o: In function `cv::Mat::release()':
Bridge1.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
Which leads me to beleive I am not referencing the libraries properly, but if that's the case what am i missing?
We are Allegory.

