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,具体设置如图:在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值