人们如何处理警告 C4793:“some_function”? : 函数编译为本机?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您想要的是这样的:
C++/CLI 项目可以包含托管和非托管部分,并且编译器会为您处理这两个部分之间的数据编组。托管入口点可以从普通的 .NET 应用程序(如 C# 和其他应用程序)调用,并且将使用垃圾收集,并且它们将调用非托管函数来完成繁重的工作。
I think what you want is this:
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.
我认为你应该抑制该警告。 MSDN 文档明确指出托管/非托管编译指示不应在 include 语句之前使用。
I think you should suppress the warning. The MSDN doc explicitly states that the managed/unmanaged pragmas should not be used before include statements.
如果无法更改现有代码文件,则可以通过禁用对显示 警告 4793。当然,只有当该文件不使用任何 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.