MiroKaku / ucxxrt

The Universal C++ RunTime library, supporting kernel-mode C++ exception-handler and STL.
MIT License
399 stars 97 forks source link

[BUG] 编译时:error LNK2038: 检测到“RuntimeLibrary”的不匹配项 #13

Closed MMitsuha closed 2 years ago

MMitsuha commented 2 years ago

Describe the bug 编译时出现ucxxrt.lib(xthrow.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MT_StaticRelease”ucxxrt.lib(throw_bad_alloc.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MT_StaticRelease”

To Reproduce Steps to reproduce the behavior: 1.切换到Debug选项 2.编译

Expected behavior 出现LNK2038错误

Screenshots image

Desktop (please complete the following information):

Additional context

已启动生成...
1>------ 已启动生成: 项目: NtLoader, 配置: Debug x64 ------
1>
1>  **************************************************
1>  *         Universal C++ RunTime (UCXXRT)         *
1>  **************************************************
1>  
1>  UCXXRT Path      : C:\Users\cz251\source\repos\NtLoader\packages\ucxxrt.2.1.2\lib\native\
1>  Platform         : x64
1>  Configuration    : Debug
1>  Tools Version    : 14.32.31326
1>  Platform Version : 10.0.22621.0
1>  Kernel Mode      : true
1>Building 'NtLoader' with toolset 'WindowsKernelModeDriver10.0' and the 'Universal' target platform.
1>KLog.cpp
1>KMemory.cpp
1>Main.cpp
1>正在生成代码...
1>ucxxrt.lib(xthrow.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MT_StaticRelease”(Main.obj 中)
1>ucxxrt.lib(throw_bad_alloc.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MT_StaticRelease”(Main.obj 中)
1>C:\Users\cz251\source\repos\NtLoader\x64\Debug\NtLoader.sys : fatal error LNK1319: 检测到 2 个不匹配项
1>已完成生成项目“NtLoader.vcxproj”的操作 - 失败。
========== “生成”: 0 成功,1 失败,0 更新,0 已跳过 ==========
MiroKaku commented 2 years ago

Debug 的项目配置缺少宏定义 _DEBUG (一般来说,VS 会默认带这个宏的)

EN: Debug's project configuration is missing the macro definition _DEBUG (usually, VS will have this macro by default)

MMitsuha commented 2 years ago

Debug 的项目配置缺少宏定义 _DEBUG (一般来说,VS 会默认带这个宏的)

EN: Debug's project configuration is missing the macro definition _DEBUG (usually, VS will have this macro by default)

但是我觉得是ucxxrt.lib是用release编译的,而我的是用debug的,所以出现了mt和mtd不对应的问题,运行库应该不是由宏来决定的吧,我切换到release编译就成功了

MiroKaku commented 2 years ago

ucxxrt的配置并没有错。_DEBUG 宏是STL的头文件里面需要的,头文件这部分并不会编译到ucxxrt

MiroKaku commented 2 years ago

Debug 的项目配置缺少宏定义 _DEBUG (一般来说,VS 会默认带这个宏的) EN: Debug's project configuration is missing the macro definition _DEBUG (usually, VS will have this macro by default)

但是我觉得是ucxxrt.lib是用release编译的,而我的是用debug的,所以出现了mt和mtd不对应的问题,运行库应该不是由宏来决定的吧,我切换到release编译就成功了

更何况,错误提示已经指出了 ucxxrt 是 debug 的,而你的 ntloader 因为缺少 _DEBUG 被认为是 release 的

1>ucxxrt.lib(xthrow.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 
值“MTd_StaticDebug”不匹配值“MT_StaticRelease”(Main.obj 中)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1>ucxxrt.lib(throw_bad_alloc.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 
值“MTd_StaticDebug”不匹配值“MT_StaticRelease”(Main.obj 中)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1>C:\Users\cz251\source\repos\NtLoader\x64\Debug\NtLoader.sys : fatal error LNK1319: 检测到 2 个不匹配项
MMitsuha commented 2 years ago

我更改了运行库,解决了,谢谢啦awa