windows clang踩坑记录
VS studio安装路径
- 准备工作
- 卸载所有的SDK,从vs studio installer中卸载,并且从设置-应用中卸载(搜索kit),并且移除
C:\Program Files (x86)\Windows Kits
目录。 - 可以使用工具删除Releases · microsoft/VisualStudioUninstaller (github.com)
- 共享组件、工具和SDK安装位置修改
进入注册表,找到表项
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\Setup
,删除项CachePath
与SharedInstallationPath
。在vs studio installer中此时即可修改安装位置。
- 系统缓存、工具和位置固定的SDK修改
- 进入注册表,找到表项
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots
,修改项KitsRoot10
、KitsRoot81
、WindowsDebuggersRoot10
等包含目录的项,**注意最后必须加\
**。
- 重新安装
- 在vs studio installer中安装SDK。
配置资源编译器
找到上述SDK安装路径(默认为
C:\Program Files (x86)\Windows Kits
),找到MSVC的资源编译器(安装路径\10\bin\10.0.22621.0\x64\rc.exe
)。复制文件地址,配置cmake编译选项
-DCMAKE_RC_COMPILER="rc_path"
或配置环境变量RC
为"rc_path"
,如果路径中有空格,注意加入引号
。
配置clang
加入环境变量
设置clion的工具链和cmake选项。
工具链:选择C编译工具为
bin\clang.exe
,C++编译工具为bin\clang++.exe
,cmake为自己安装的cmake路径。cmake选项:参考上述配置资源编译器中的选项。
- 编译选项
由于找不到libc,所以需要借用一下mingw的libc(需要保证mingw安装且加入环境变量)加入编译选项
-target x86_64-pc-windows-gnu
。由于报警告
Warning: corrupt .drectve at end of def file
,使用编译选项-fuse-ld=lld
指定链接器。所以,最终编译命令可以为
clang++ .\test.cpp -target x86_64-pc-windows-gnu -std=c++20 -fuse-ld=lld
。
参考
Releases · microsoft/VisualStudioUninstaller (github.com)
Visual Studio安装时,不能更改共享组件、工具和SDK的位置_共享组件、工具和sdk位置-CSDN博客
更改windows kit通用安装路径-腾讯云开发者社区-腾讯云 (tencent.com)
忍者:找不到CMAKE_RC_COMPILER-腾讯云开发者社区-腾讯云 (tencent.com)
Releases · llvm/llvm-project (github.com)
Clion 2020.3:如何设置Clang编译器 - 知乎 (zhihu.com)
Windows下clang使用 - 知乎 (zhihu.com)
- Title: windows clang踩坑记录
- Author: Ethereal
- Created at: 2024-03-16 20:47:46
- Updated at: 2024-03-17 15:48:30
- Link: https://ethereal-o.github.io/2024/03/16/windows-clang踩坑记录/
- License: This work is licensed under CC BY-NC-SA 4.0.