Windows11下用WSL的原生GNU工具链来实现C系列程序的开发
事情的起因
cygwin和mingw-w64在Windows平台下始终无法解决编码问题,出现中文目录文件名可以运行但无法调试。Clion出现无法调和的bug。
故决定使用WSL获取原生的体验。
使用WSL2
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
下载安装Linux内核更新包
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
重启电脑
在Microsoft Store
安装Ubuntu22.04LTS
打开进行一些基本的配置
安装GNU工具链
sudo apt install gcc clang cmake gdb
Ubuntu库的cmake版本为3.22,而Clion需要的是3.23以上,当我安装最新的3.24又显示不支持🤣,所以下载Github编译好的3.23的包
https://github.com/Kitware/CMake/releases
wget https://github.com/Kitware/CMake/releases/download/v3.23.3/cmake-3.23.3-linux-x86_64.tar.gz
tar -zxvf cmake-3.23.3-linux-x86_64.tar.gz
# 创建软链接
sudo ln -s /mnt/c/Users/Administrator/cmake-3.23.3-linux-x86_64/bin/cmake /usr/bin/cmake
Clion添加工具链中可以自动识别已安装的WSL
在VSCode中使用WSL
- 可以通过Remote-WSL插件通过SSH的方式连接到WSL
- 通过CodeRunner等的配合
以下为settings.json中的终端配置(必须按照terminal.integrated.defaultProfile.windows的提示书写名称)
"terminal.integrated.profiles.windows": {
"PowerShell": {
"path": "pwsh.exe",
"args": [
"-nologo"
]
},
"Ubuntu-22.04 (WSL)": {
"path": "wsl.exe",
"args": []
}
},
"terminal.integrated.defaultProfile.windows": "Ubuntu-22.04 (WSL)",
以下为CodeRunner的map的书写
# 必须加的一条路径指定
"code-runner.terminalRoot": "/mnt/",
# code-runner自带的clear-output无法在终端生效
"code-runner.executorMap": {
"c": "clear && cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
以下为调试的配置的书写
~~~
因觉得不想让WSL污染本地开发环境,故停止继续研究😂
记录参考资料
本文作者:TomZz
本文链接:https://www.cnblogs.com/Tom-Zz/p/16574976.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步