人们如何处理警告 C4793:“some_function”? : 函数编译为本机?

发布于 2024-08-31 13:52:03 字数 404 浏览 9 评论 0原文

我正在使用 OpenCV 库及其头文件之一 cxoperations.hpp,如果我的 C++ 项目是使用 CLR 支持进行编译。我可以通过像这样包含 OpenCV 标头来防止警告:

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

但是实际使用 OpenCV 的项目不是使用 CLR 支持编译的,它是一个本机 C++ 静态库。具有 CLR 支持并且在没有 pragma 语句的情况下生成此警告的项目仅使用此静态库。所以我对这个警告的产生感到有点惊讶,特别是考虑到整个静态库不是用 CLR 支持编译的,但只有这个标头导致了问题。

因此,这个解决方案对我来说似乎不是最优的。这是您处理此警告的方式,还是您可以推荐更好的做法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少跟Wǒ拽 2024-09-07 13:52:03

我认为您想要的是这样的:

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

C++/CLI 项目可以包含托管和非托管部分,并且编译器会为您处理这两个部分之间的数据编组。托管入口点可以从普通的 .NET 应用程序(如 C# 和其他应用程序)调用,并且将使用垃圾收集,并且它们将调用非托管函数来完成繁重的工作。

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.

缱绻入梦 2024-09-07 13:52:03

我认为你应该抑制该警告。 MSDN 文档明确指出托管/非托管编译指示不应在 include 语句之前使用。

#pragma warning(push)
#pragma warning(disable: 4793) // methods are compiled as native (clr warning)
#include <cv.h>
#pragma warning(pop)

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)
无远思近则忧 2024-09-07 13:52:03

如果无法更改现有代码文件,则可以通过禁用对显示 警告 4793。当然,只有当该文件不使用任何 CLR 功能时,这才有效。

要禁用对特定文件的 CLR 支持,请在解决方案资源管理器中找到该文件,右键单击并打开其属性页。将“公共语言运行时支持”设置为“无公共语言运行时支持”。不要忘记对所有配置所有平台执行此操作。

关闭每个文件的 CLR 支持

If you cannot change existing code files, you can get rid of the warning by disabling CLR support for the specific file that shows warning 4793. Of course, this only works if this file does not make any use of CLR features.

To disable CLR support for a specific file, locate it in Solution Explorer, right-click and open its Property Pages. Set Common Language RunTime Support to No Common Language RunTime Support. Don't forget to do this for All Configurations and All Platforms.

Turn off CLR support per file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文