Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do people handle warning C4793: 'some_function' : function compiled as native?

I'm using the OpenCV library and one of its header files, cxoperations.hpp, generates "warning C4793: 'anonymous namespace'::CV_XADD' : function compiled as native", if my C++ project is compiled with CLR support. I can prevent the warning by surrounding the OpenCV header include like this:

#pragma managed(push,off)
#include <cv.h>
#pragma managed(pop)

But the project that actually uses OpenCV isn't compiled with CLR support, it's a native C++ static library. The project that does have CLR support, and generates this warning without the pragma statements, simply uses this static library. So I'm a bit surprised that the warning was created at all, especially given the fact that the entire static library is not compiled with CLR support, and yet it's only this one header that causes the problem.

Thus this solution seems sub-optimal to me. Is this how you would handle this warning, or can you recommend a better practice?

like image 959
Michael Repucci Avatar asked May 06 '10 22:05

Michael Repucci


2 Answers

I think what you want is this:

#pragma unmanaged
#include <cv.h>
#pragma managed
// managed code wrapping unmanaged opencv functions

A C++/CLI project can contain both managed and unmanaged parts, and the compiler takes care of marshalling data between the 2 for you. The managed entry points will be callable from normal .NET apps (like C# and the rest) and will use garbage collection, and they'll call unmanaged functions to do the heavy lifting.

like image 146
Blindy Avatar answered Oct 12 '22 22:10

Blindy


I think you should suppress the warning. The MSDN doc explicitly states that the managed/unmanaged pragmas should not be used before include statements.

#pragma warning(push)
#pragma warning(disable: 4793) // methods are compiled as native (clr warning)
#include <cv.h>
#pragma warning(pop)
like image 37
fmuecke Avatar answered Oct 12 '22 23:10

fmuecke