更新时间:2025-05-21 GMT+08:00
毕昇编译器
毕昇编译器(bisheng compiler)是华为提供的一款提供高性能、高可信及易扩展的编译器工具链。毕昇编译器引入了多种编译技术,支持C/C++/Fortran编译语言。
约束限制
HCE原生的clang编译语言和毕昇编译器提供的clang编译语言不能同时使用。如果您已经安装原生的clang编译语言并需要使用它,就不能安装毕昇编译器。
在安装了毕昇编译器之后,如果需要使用原生的clang编译语言,可执行rpm -e bisheng-compiler命令删除毕昇编译器,然后打开新终端。在新终端中,就可以使用原生的clang编译语言。
安装毕昇编译器
- 确认repo源配置正常。
请检查默认的/etc/yum.repos.d/hce.repo配置文件中参数是否正确,正确的配置如下。
[base] name=HCE $releasever base baseurl=https://repo.huaweicloud.com/hce/$releasever/os/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/hce/$releasever/os/RPM-GPG-KEY-HCE-2 [updates] name=HCE $releasever updates baseurl=https://repo.huaweicloud.com/hce/$releasever/updates/$basearch/ ......
- 执行yum -y install bisheng-compiler命令安装工具。
- 执行source /usr/local/bisheng-compiler/env.sh命令,导入环境变量。
如果打开了新的终端,需要在新的终端重新导入环境变量才能正常使用毕昇编译器。
- 检查工具是否安装成功。
使用毕昇编译器
- 编译运行C/C++程序,以C程序为例
- 添加以下内容到hello.c文件中。
#include <stdio.h> int main() { printf("Hello, World! This is a C program.\n"); return 0; }
- 编译hello.c。
clang hello.c -o hello.o
- 执行hello.o。
./hello.o
- 添加以下内容到hello.c文件中。
- 编译运行Fortran程序
- 添加以下内容到hello.f90文件中。
program hello print *, "Hello, World! This is a Fortran program." end program hello
- 编译hello.f90。
flang hello.f90 -o hello.o
- 执行hello.o。
./hello.o
- 添加以下内容到hello.f90文件中。
- 指定链接器。
毕昇编译器指定的链接器是LLVM的lld,若不指定它则使用默认的ld。
clang -fuse-ld=lld hello.c -o hello.o ./hello.o
父主题: 工具类