CLion 使用 WSL
文章目录
CLion 在安装时会自带 MinGW,MinGW 是 gcc 在 Window 上的版本,支持 C 语言在 Window 平台的编译。但由于跟 posix 标准不完全一致,如果所运行的 C 语言程序中包含了 socket.h 等库,MinGW 则没办法编译。所以我们可以改为通过使用 WSL 来进行编译。
首先将 WSL 的 Ubuntu 的官方源修改为阿里的源:
sudo vim /etc/apt/source
修改为:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
记得更新系统:
sudo apt-get update
sudo apt-get upgrade
安装 gcc:
sudo apt-get install build-essential
因为在 Clion 中使用 cmake 会提示错误,这里我们建议使用 ninja
sudo apt install ninja-build
然后在设置中找到 Toolchains ,新增一个 WSL 以替换原来的 MinGW,具体设置如图:
参考:
文章作者 梧桐碎梦
上次更新 2022-09-25 17:23:45