利用msys2安装clang和llvm编译器

10 篇文章 0 订阅

很多文章介绍了如何从clang官网安装clang和llvm,不过最后都会说缺少include和lib,需要用别的方法。其实用msys2就可以下载基于MinGW-w64项目的clang和llvm。步骤如下:

1. 到msys2官网下载最新版本msys2: https://www.msys2.org/;

2. 安装msys2-x64:

3. 启动msys2运行环境:

4. 编辑etc\pacman.conf文件,在后面添加内容如下:

   [clang32]
   Include = /etc/pacman.d/mirrorlist.clang32

   [clang64]
   Include = /etc/pacman.d/mirrorlist.clang64

5. 在etc\pacman.d\目录下创建文件mirrorlist.clang32,内容如下:

##
## 32-bit clang repository mirrorlist
##

## Primary
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/mingw/clang32/
## Mirrors
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang32/
Server = http://mirrors.ustc.edu.cn/msys2/mingw/clang32/
Server = http://mirror.bit.edu.cn/msys2/mingw/clang32/
Server = https://downloads.sourceforge.net/project/msys2/REPOS/MINGW/clang32/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/mingw/clang32/
Server = https://mirror.yandex.ru/mirrors/msys2/mingw/clang32/
Server = https://mirror.selfnet.de/msys2/mingw/clang32/
Server = https://mirror.jmu.edu/pub/msys2/mingw/clang32/
Server = https://ftp.cc.uoc.gr/mirrors/msys2/mingw/clang32/
Server = https://ftp.acc.umu.se/mirror/msys2.org/mingw/clang32/
Server = https://mirrors.piconets.webwerks.in/msys2-mirror/mingw/clang32/
Server = https://quantum-mirror.hu/mirrors/pub/msys2/mingw/clang32/
Server = https://mirrors.dotsrc.org/msys2/mingw/clang32/ 
Server = https://mirror.ufro.cl/msys2/mingw/clang32/
Server = https://mirror.clarkson.edu/msys2/mingw/clang32/
Server = https://ftp.nluug.nl/pub/os/windows/msys2/builds/mingw/clang32/
Server = https://download.nus.edu.sg/mirror/msys2/mingw/clang32/
Server = https://ftp.osuosl.org/pub/msys2/mingw/clang32/
Server = https://fastmirror.pp.ua/msys2/mingw/clang32/
Server = https://repo.msys2.org/mingw/clang32/

6. 在etc\pacman.d\目录下创建文件mirrorlist.clang64,内容如下:

##
## 64-bit clang repository mirrorlist
##

## Primary
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/mingw/clang64/
## Mirrors
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang64/
Server = http://mirrors.ustc.edu.cn/msys2/mingw/clang64/
Server = http://mirror.bit.edu.cn/msys2/mingw/clang64/
Server = https://downloads.sourceforge.net/project/msys2/REPOS/MINGW/clang64/
Server = https://www2.futureware.at/~nickoe/msys2-mirror/mingw/clang64/
Server = https://mirror.yandex.ru/mirrors/msys2/mingw/clang64/
Server = https://mirror.selfnet.de/msys2/mingw/clang64/
Server = https://mirror.jmu.edu/pub/msys2/mingw/clang64/
Server = https://ftp.cc.uoc.gr/mirrors/msys2/mingw/clang64/
Server = https://ftp.acc.umu.se/mirror/msys2.org/mingw/clang64/
Server = https://mirrors.piconets.webwerks.in/msys2-mirror/mingw/clang64/
Server = https://quantum-mirror.hu/mirrors/pub/msys2/mingw/clang64/
Server = https://mirrors.dotsrc.org/msys2/mingw/clang64/ 
Server = https://mirror.ufro.cl/msys2/mingw/clang64/
Server = https://mirror.clarkson.edu/msys2/mingw/clang64/
Server = https://ftp.nluug.nl/pub/os/windows/msys2/builds/mingw/clang64/
Server = https://download.nus.edu.sg/mirror/msys2/mingw/clang64/
Server = https://ftp.osuosl.org/pub/msys2/mingw/clang64/
Server = https://fastmirror.pp.ua/msys2/mingw/clang64/
Server = https://repo.msys2.org/mingw/clang64/

7. 同步包数据库,在msys2-shell中运行命令: pacman -Sy

8. 运行:pacman -Syu,运行成功后会自动关闭msys2窗口;

9. 重新运行msys2-shell;

10. 更新msys2,运行:pacman -Su

11. 若要安装64-bit clang,运行:pacman -S mingw-w64-clang-x86_64-toolchain

12. 若要安装32-bit clang,运行:pacman -S mingw-w64-clang-i686-toolchain。

至此,clang安装完毕,文件均安装在msys2\clang64目录或msys2\clang32目录下。浏览目录下的文件可知,是完整的clang+llvm编译器,包括了所有的include和lib。

可以在命令行检查下载的clang和llvm版本:

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值