[ 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
epinux@Debian-70-wheezy-64-minimal:~/dev/opencv/build2$
The error above is from a src build on a debian sid 64bit linux, using git master for both ospencv and opencv_contrib
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.
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
Happy to help! Thank you for the explanation, by the way.
Most helpful comment
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):
or use something like this: