NVCC Won't compile OpenCV

Hi there

I am trying to integrate CUDA into a OpenCV project. However when compiling I get a couple of errors.

c:\opencv2.0\include\opencv\cxoperations.hpp(2469): error: more than one instance of overloaded function “std::abs” matches the argument list:
function “abs(long double)”
function “abs(float)”
function “abs(double)”
function “abs(long)”
function “abs(int)”
argument types are: (ptrdiff_t)

and

c:\opencv2.0\include\opencv\cxoperations.hpp(1137): error: no operator “=” matches these operands
operand types are: const cv::Range = cv::Range

I am a bit confused as I thought that my host code would be passed to the Visual Studio compiler, which on its own in a normal C++ compiles OpenCV just fine.

Any ideas what is happening here, and how to remedy?

Thanks

NVCC does not support C++, which includes C++ headers …

Include only C headers in CUDA files and you have no problems.

Probably you need only the type definitions in your CUDA program.

In this case use – > #include “cxtypes.h” <-- and it will work fine.

The other possibility is to split your Programm in a C++ part and C/CUDA part.

Look into the CUDA SDK, there is an example cppIntegration.

I believe line 1137 is a bug in the OpenCV header. You can modify the header to temporarily correct the issue by changing the left side of the statement there to:

const_castcv::Range&( r ) =

The first error doesn’t come up on my machines – but you can probably disambiguate and submit the patch to the OpenCV maintainers. The fact that the cast is ambiguous suggests that it should be fixed, even if it compiles quietly in other contexts.

PS: I have also found it useful to add

#undef SSE2

#undef SSE

#undef MMX

before including OpenCV headers (since NVCC chokes on SSE built-ins). With this handful of hacks, OpenCV interoperates reasonably with CUDA on my system.

Cheers,

Adam