C++ CLR 不会在调试之外编译

标签 c++ winforms compilation clr

我正在尝试使用 clr 构建应用程序,并尝试使用多线程 DLL (/MD) 对其进行编译,但它不起作用。它一直给我这个:

WindowsFormsApplication3.obj : error LNK2020: unresolved token (0A000796) "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ)
WindowsFormsApplication3.obj : error LNK2020: unresolved token (0A000797) "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ)
WindowsFormsApplication3.obj : error LNK2001: unresolved external symbol "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ)
D:\Users\Student\Documents\Visual Studio 2012\Projects\WindowsFormsApplication3\Debug\WindowsFormsApplication3.exe : fatal error LNK1120: 3 unresolved externals

当我用/MDd 编译时它工作得很好。我查看了错误的含义,但问题出在我无法访问的文件中。是我其他设置有误还是什么?

编辑:我想通了。 _DEBUG 是在属性中的预处理器定义下定义的。谢谢 Balog 的建议——我将不得不重新考虑我是如何做这件事的。很抱歉我不太了解细节,这是我很长一段时间以来第一个使用 gcc 以外的编译器的应用程序。

最佳答案

如果您编译程序进行调试(即 _DEBUG 定义),CRT 可能会使用调用该 CrtDebugReport 函数的代码。这仅在 dll 的调试版本中定义。

当然,您可以直接放入缺失函数的定义来关闭链接器,但正常的方法是使用一致的设置进行编译。为什么要强制使用/MD 而不是/MDd?

关于C++ CLR 不会在调试之外编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17386008/

相关文章:

c# - 在 xaml 项目中使用 CoreWindow 交换链,为什么没有绘制?

c++ - 使用 OpenCV 在 C++ 中绘制图像绿色分量的直方图

c# - 如何为用户控件设置默认值?

android - Kotlin 安卓编译

c++ - 构造函数 Foo::Foo 接收到对 Foo 的引用但不是复制构造函数

c++ - 静态函数链接器错误

.net - 我可以将节点文本包装在WinForms TreeView中吗

c# - 如何在 WinCE Compact Framework 3.5 中标记用户控件的默认事件

android - 如何修复 Android Studio 中 Flutter 的 AndroidX 兼容性?

compilation - 当一个实体上有多个架构时会发生什么?