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

error building ```opencv_contrib/modules/tracking/include/opencv2/tracking/tracker.hpp``` #618

epifanio opened this Issue Mar 30, 2016 · 4 comments


3 participants
Copy link

epifanio commented Mar 30, 2016

[ 98%] Built target opencv_test_matlab
[ 98%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
In file included from /home/epinux/dev/opencv_contrib/modules/tracking/include/opencv2/tracking/tracker.hpp:48:0,
                 from /home/epinux/dev/opencv/build2/modules/python2/pyopencv_generated_include.h:50,
                 from /home/epinux/dev/opencv/modules/python/src2/cv2.cpp:12:
/home/epinux/dev/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected unqualified-id before ‘>’ token
 #define  sign(s)  ((s > 0 ) ? 1 : ((s<0) ? -1 : 0))
/home/epinux/dev/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected ‘)’ before ‘>’ token
/home/epinux/dev/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected ‘)’ before ‘>’ token
modules/python2/CMakeFiles/opencv_python2.dir/build.make:296: recipe for target 'modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o' failed
make[2]: *** [modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o] Error 1
CMakeFiles/Makefile2:13133: recipe for target 'modules/python2/CMakeFiles/opencv_python2.dir/all' failed
make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2


This comment has been minimized.

Copy link

epifanio commented Mar 30, 2016

The error above is from a src build on a debian sid 64bit linux, using git master for both ospencv and opencv_contrib


This comment has been minimized.

Copy link

rexroni commented Apr 9, 2016

Found the problem, it is a macro re-definition issue. There are three places where #define sign(...) occurs. The first two are from the main opencv repo:

opencv/modules/core/test/test_eigen.cpp:#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
opencv/modules/core/test/test_countnonzero.cpp:#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1

The last is from the opencv_contrib repo:

opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:#define  sign(s)  ((s > 0 ) ? 1 : ((s<0) ? -1 : 0))

The reason that the error is so cryptic is because the preprocessor is apparently expanding the sign(s) in the definition #define sign(s)..., leading to obvious problems

What I did to fix my build was to change the #define sign(s) ... to the abbreviated version #define sgn(s)..., which required two lines to be changed from a sign() call to a sgn() call in opencv_contrib/modules/tracking/src/onlineMIL.cpp. The two changes were on lines 310, and 339.

I am not sure if there is a more appropriate way to do it, but I was not able to find a way to test for the definition of a function-like macro (so as to avoid re-defining it). Perhaps, if the macro is only called twice, it may be done away with and just be manually expanded in the code.


This comment has been minimized.

Copy link

alalek commented Apr 9, 2016

Thanks for investigation!

This definition should go away from public header file and moved into .cpp file directly.

The correct form of macro is (put arg into brackets):

#define  CV_SIGN(s)  (((s) > 0) ? 1 : (((s)<0) ? -1 : 0))

or use something like this:

namespace {
    template<typename T>
    CV_INLINE int sign(const T v) {
        return (v > 0) ? 1 : ((v < 0) ? -1 : 0);
} // anon namespace

@alalek alalek added the bug label Apr 9, 2016


This comment has been minimized.

Copy link

rexroni commented Apr 9, 2016

Happy to help! Thank you for the explanation, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment