我正在尝试使用 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/