Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiling opencv gives error #56

Closed
eix128 opened this issue Jun 15, 2015 · 6 comments
Closed

compiling opencv gives error #56

eix128 opened this issue Jun 15, 2015 · 6 comments
Labels

Comments

@eix128
Copy link

eix128 commented Jun 15, 2015

hi , i when i tried to compile opencv from javacpp , i got error as shown below:

C:\Users\Kadir\Desktop\javacpp-presets\opencv\target\classes\org\bytedeco\javacp
p\jniopencv_objdetect.cpp(8865) : warning C4244: 'initializing' : conversion fro
m 'jlong' to 'jint', possible loss of data
C:\Users\Kadir\Desktop\javacpp-presets\opencv\target\classes\org\bytedeco\javacp
p\jniopencv_objdetect.cpp(9036) : warning C4244: 'initializing' : conversion fro
m 'jlong' to 'jint', possible loss of data
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:jniopencv_objdetect.dll
/ltcg
/dll
/implib:jniopencv_objdetect.lib
/OUT:C:\Users\Kadir\Desktop\javacpp-presets\opencv\target\classes\org\bytedeco\j
avacpp\windows-x86\jniopencv_objdetect.dll
/LIBPATH:C:\Users\Kadir\Desktop\javacpp-presets\opencv/cppbuild/windows-x86/lib/

opencv_world300.lib
jniopencv_objdetect.obj
   Creating library jniopencv_objdetect.lib and object jniopencv_objdetect.exp
jniopencv_objdetect.obj : error LNK2001: unresolved external symbol "public: __t
hiscall cv::DetectionBasedTracker::Parameters::Parameters(void)" (??0Parameters@
DetectionBasedTracker@cv@@QAE@XZ)
C:\Users\Kadir\Desktop\javacpp-presets\opencv\target\classes\org\bytedeco\javacp
p\windows-x86\jniopencv_objdetect.dll : fatal error LNK1120: 1 unresolved extern
als

C:\Users\Kadir\Desktop\javacpp-presets\opencv>
@saudet
Copy link
Member

saudet commented Jun 16, 2015

Right, that seems to be a bug in OpenCV... I guess we'll have to create a patch for that. Would you be able to look into this? Thanks!

@eix128
Copy link
Author

eix128 commented Jun 16, 2015

why not.Yes i can test

@jpsacha
Copy link
Member

jpsacha commented Jun 21, 2015

@saudet Why do you think it is a bug in OpenCV?

I did a little experiment. The linker complains about

cv::DetectionBasedTracker::Parameters::Parameters(void)

I when to the downloaded header detection_based_tracker.hpp and commented out constructor in struct Parameters that was a potential problem:

        struct Parameters
        {
            int maxTrackLifetime;
            int minDetectionPeriod; 
//            Parameters();
        };

Then I run clean and install -projects .,opencv. Now the build completed without errors (not counting some eror character in in comments in persistance.hpp that I corrected too).
The thing that I do not understand is that in both cases (with and without Parameters(); commented) the generated wrapper code was almost the same. Not counting different comment and order of declarations the class for Parameters was almost identical. Original:

        @NoOffset public static class Parameters extends Pointer {
            static { Loader.load(); }
            public Parameters(Pointer p) { super(p); }
            public Parameters(int size) { allocateArray(size); }
            private native void allocateArray(int size);
            @Override public Parameters position(int position) {
                return (Parameters)super.position(position);
            }

            public native int maxTrackLifetime(); public native Parameters maxTrackLifetime(int maxTrackLifetime);
            public native int minDetectionPeriod(); public native Parameters minDetectionPeriod(int minDetectionPeriod); //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0

            public Parameters() { allocate(); }
            private native void allocate();
        }

and with Parameters(); commented (order of declarations rearranged to match above):

        public static class Parameters extends Pointer {
            static { Loader.load(); }
            public Parameters(Pointer p) { super(p); }
            public Parameters(int size) { allocateArray(size); }
            private native void allocateArray(int size);
            @Override public Parameters position(int position) {
                return (Parameters)super.position(position);
            }

            public native int maxTrackLifetime(); public native Parameters maxTrackLifetime(int maxTrackLifetime);
            public native int minDetectionPeriod(); public native Parameters minDetectionPeriod(int minDetectionPeriod); //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0

            public Parameters() { allocate(); }
            private native void allocate();
//            Parameters();
        }

The only difference is @NoOffset annotation (no idea what that actually does).

Can we just fix the issue by commenting out Parameters(); in detection_based_tracker.hpp? When pre-build binaries are used this should have no impact at run-time.

@jduke32 Can you check out if commenting out Parameters(); works for you?

@saudet
Copy link
Member

saudet commented Jun 21, 2015

@jpsacha Thanks for starting to look into this! It's a bug in OpenCV because it doesn't give us access to the cv::DetectionBasedTracker::Parameters::Parameters() constructor defined in the .cpp file. Maybe we have to put CV_EXPORT on the nested class as well? I'm not sure what MSVC expects, but something like that is what needs to be adjusted.

jpsacha added a commit to jpsacha/javacpp-presets that referenced this issue Jun 22, 2015
OpenCV is build from source on Windows. Patches are applied co correct issues in OpenCV.
@jpsacha
Copy link
Member

jpsacha commented Jun 22, 2015

I create PR that adds building OpenCV binaries from source on Windows, as it is done on other platforms. Before the build two patches are applied to correct issues that were breaking creation of wrappers. One reported earlier, and one more found later. You will need to install Visual Studio 2013 (community edition works) and Windows version of CMake to generate Visual Studio project correctly.

Works fine for me, tested with some sample code from the Cookbook Examples.

jpsacha added a commit to jpsacha/javacpp-presets that referenced this issue Jun 25, 2015
jpsacha added a commit to jpsacha/javacpp-presets that referenced this issue Jun 27, 2015
@saudet saudet added the bug label Jul 4, 2015
@saudet
Copy link
Member

saudet commented Jul 17, 2015

Fix included in version 1.0. Thanks @jpsacha for the fix and the build!! 👍

@saudet saudet closed this as completed Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants