在Windows上使用clang时选择MSVC运行时
我目前正在尝试使用Makefiles使用MSVC和Clang编译一个较大的项目。该项目包含几个静态的,共享的库和可执行文件。 用Linux下的Clang和NDK(Windows/linux)在Linux下编译项目,效果很好。现在,我试图在Windows上编译整个项目。
我所做的
- 安装LLVM 14.0.5
- 安装Visual Studio Community 2022
- 设置Makefiles将LLVM用于Windows
- MakeFiles正在引用Windows套件,以确保使用link.exe通过lld-link.exe确保Windows SDK +
Clangs clangs clangs clangs clangs clangs clang selects clangs selects selects runtime selects runtimes (MSVC /MT [D]开关),但我需要编译项目以使用MSVC /MD [D] Switch提供的运行时。 我的问题是,如何通过编译标志或让某些预处理或其他方式选择运行时?
lld-link: error: /failifmismatch: mismatch detected for
RuntimeLibrary':
>>> test.cpp.o has value MTd_StaticDebug
>>> libDxBc.lib(api.obj) has value MDd_DynamicDebug
libdxbc.lib是使用Visual Studio构建的 链接命令
lld-link.exe @linker.list libDxBc.lib -ignore:LNK4217 -libpath:"c:/Program Files/Microsoft Visual Studio/2022/Community"/VC/Tools/MSVC/14.32.31326/lib/x64 -libpath:"C:/Program Files (x86)/Windows Kits/10"/Lib/10.0.20348.0/ucrt/x64 -libpath:"C:/Program Files (x86)/Windows Kits/10"/Lib/10.0.20348.0/um/x64 -machine:x64 -subsystem:console -nodefaultlib msvcrtd.lib vcruntime.lib ucrtd.lib legacy_stdio_definitions.lib legacy_stdio_wide_specifiers.lib oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib vcomp.lib rpcrt4.lib wsock32.lib setupapi.lib imagehlp.lib winmm.lib Shlwapi.lib -dll -out:test.dll -implib:test.lib -def:test.def
看起来像该信息是编译过程的一部分,因此test.cpp.o包含此信息
解决方案
- define -d_dll define -d_dll compile link for compile link。
- 使用-nodefaultlib msvcrtd.lib vcruntime.lib ucrtd.lib
I am currently try to compile a larger project using MSVC and clang via Makefiles. The project contains several static, shared libraries and executables.
Compiling the project with clang under Linux and using NDK (Windows/Linux) works quit well. Now I am trying to compile the whole Project on Windows.
What I did
- install LLVM 14.0.5
- install Visual Studio Community 2022
- setup makefiles to use LLVM for windows
- makefiles are referencing to Windows Kit to ensure a Windows SDK + using link.exe through lld-link.exe
The problem is that clang selects msvcrt runtime (MSVC /MT[d] switch) but I need to compile the projects to use runtime provided by MSVC /MD[d] switch.
My question is, how can I select the runtime either through compile flag or by having some pre-processor define or someting else?
lld-link: error: /failifmismatch: mismatch detected for
RuntimeLibrary':
>>> test.cpp.o has value MTd_StaticDebug
>>> libDxBc.lib(api.obj) has value MDd_DynamicDebug
libDxBc.lib was build using visual studio
link command
lld-link.exe @linker.list libDxBc.lib -ignore:LNK4217 -libpath:"c:/Program Files/Microsoft Visual Studio/2022/Community"/VC/Tools/MSVC/14.32.31326/lib/x64 -libpath:"C:/Program Files (x86)/Windows Kits/10"/Lib/10.0.20348.0/ucrt/x64 -libpath:"C:/Program Files (x86)/Windows Kits/10"/Lib/10.0.20348.0/um/x64 -machine:x64 -subsystem:console -nodefaultlib msvcrtd.lib vcruntime.lib ucrtd.lib legacy_stdio_definitions.lib legacy_stdio_wide_specifiers.lib oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib vcomp.lib rpcrt4.lib wsock32.lib setupapi.lib imagehlp.lib winmm.lib Shlwapi.lib -dll -out:test.dll -implib:test.lib -def:test.def
Looks like the information is part of the compile process so test.cpp.o contains this information
SOLUTION
- define -D_DLL for compile
- link using -nodefaultlib msvcrtd.lib vcruntime.lib ucrtd.lib
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论