English 中文(简体)
Why won t OpenCV compile in NVCC?
原标题:

I am trying to integrate CUDA and openCV in a project. Problem is openCV won t compile when NVCC is used, while a normal c++ project compiles just fine. This seems odd to me, as I thought NVCC passed all host code to the c/c++ compiler, in this case the visual studio compiler.

The errors I get are?

c:opencv2.0includeopencvcxoperations.hpp(1137): error: no operator "=" matches these operands operand types are: const cv::Range = cv::Range

c:opencv2.0includeopencvcxoperations.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)

So my question is why the difference considering the same compiler (should be) is being used and secondly how I could remedy this.

问题回答

In general I would recommend keeping separation between host code and CUDA code, only using nvcc for the kernels and host "wrappers". This is particularly easy with Visual Studio, create your project as normal (e.g. a Console application) and then implement your application in .cpp files. When you want to run a CUDA function, create the kernel and a wrapper in one or more .cu files. The Cuda.rules file provided with the SDK will automatically enable VS to compile the .cu files and link the result with the rest of the .cpp files.

NVCC passes C++ code through to the host compiler, but it has to first parse and understand the code. Unfortunately, NVCC has troubles with STL. If at all possible, separate code that makes use of STL into .cpp files and have those compiled with Visual Studio (without passing them first through NVCC).

Compile the .cu code as a library and then link it to the main program. I suggest to use cmake as it makes the process a breeze

There s a project hosted at cuda-grayscale that shows how to integrate OpenCV + CUDA together. If you download the sources check the Makefile:

g++ $(CFLAGS) -c main.cpp -o Debug/main.o
nvcc $(CUDAFLAGS) -c kernel_gpu.cu -o Debug/kernel_gpu.o
g++ $(LDFLAGS) Debug/main.o Debug/kernel_gpu.o -o Debug/grayscale

It s a very simple project that demonstrates how to separate regular C++ code (OpenCV and stuff) from the CUDA code and compile them.

So there s no easy way to use nvcc to compile your current C++ code, you have to write wrappers and compile them using nvcc, while you compile the rest of your code using g++ or what-have-you?





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签