Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Issue creating shared opencv and JNI library

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:

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.
Oops my bad. I thought you were looking up the *.so and not creating it.
(Apr 10, 2015 11:49 AM)g4143 Wrote:  Oops my bad. I thought you were looking up the *.so and not creating it.

I'm actually linking to the .a (archive) file. I'm in the middle of running make to build a set of linked libraries so I'll see how that goes.
We are Allegory.
Did you check out this Ubuntu link which shows you how to compile?

https://help.ubuntu.com/community/OpenCV


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by _NZT_Dec 18, 2020 02:42 AM 4 119 Dec 18, 2020 02:42 AM
Last Post: The-Criminal
[C] by phisnNov 11, 2020 08:44 AM 1 165 Nov 11, 2020 08:44 AM
Last Post: HFDone
[Python] by dondevetoJul 12, 2020 02:28 PM 3 124 Jul 12, 2020 02:28 PM
Last Post: dondeveto