
# 毕昇编译器
毕昇编译器（bisheng compiler）是华为提供的一款提供高性能、高可信及易扩展的编译器工具链。毕昇编译器引入了多种编译技术，支持C/C++/Fortran编译语言。
#### 约束限制
HCE原生的clang编译器和毕昇编译器提供的clang编译器不能同时使用。如果您已经安装原生的clang编译器并需要使用它，就不能安装毕昇编译器。
在安装了毕昇编译器之后，如果需要使用原生的clang编译器，可执行**rpm -e bisheng-compiler**命令删除毕昇编译器，然后打开新终端。在新终端中，就可以使用原生的clang编译器。
#### 安装毕昇编译器
1. 确认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/
   enabled=1
   gpgcheck=1
   gpgkey=https://repo.huaweicloud.com/hce/$releasever/updates/RPM-GPG-KEY-HCE-2
    
   [debuginfo]
   name=HCE $releasever debuginfo
   baseurl=https://repo.huaweicloud.com/hce/$releasever/debuginfo/$basearch/
   enabled=0
   gpgcheck=1
   gpgkey=https://repo.huaweicloud.com/hce/$releasever/debuginfo/RPM-GPG-KEY-HCE-2
   ```
   ![](https://support.huaweicloud.com/usermanual-hce/public_sys-resources/note_3.0-zh-cn.png)
   HCEOS 3.0的配置中，RPM-GPG-KEY-HCE-2换成RPM-GPG-KEY-HCE-3。
   
2. 执行**yum -y install bisheng-compiler**命令安装工具。
3. 执行**source /usr/local/bisheng-compiler/env.sh** 命令，导入环境变量。
   ![](https://support.huaweicloud.com/usermanual-hce/public_sys-resources/note_3.0-zh-cn.png)
   如果打开了新的终端，需要在新的终端重新导入环境变量才能正常使用毕昇编译器。
   
4. 检查工具是否安装成功。 执行**clang -v**查看工具的版本号。若返回结果包含毕昇编译器版本信息，表示工具安装成功。
   
 
#### 使用毕昇编译器
1. 编译运行C/C++程序，以C程序为例。
   1. 添加以下内容到hello.c文件中。
      ```
      #include <stdio.h>
      int main() {
          printf("Hello, World! This is a C program.\n");
          return 0;
      }
      ```
      
   
   2. 编译hello.c。
      ```
      clang hello.c -o hello.o
      ```
      
   
   3. 执行hello.o。
      ```
      ./hello.o
      ```
      
    
2. 编译运行Fortran程序。
   1. 添加以下内容到hello.f90文件中。
      ```
      program hello
          print *, "Hello, World! This is a Fortran program."
      end program hello
      ```
      
   
   2. 编译hello.f90。
      ```
      flang hello.f90 -o hello.o
      ```
      
   
   3. 执行hello.o。
      ```
      ./hello.o
      ```
      
    
3. 指定链接器。 毕昇编译器指定的链接器是LLVM的lld，若不指定它则使用默认的ld。
   ```
   clang -fuse-ld=lld hello.c -o hello.o
   ./hello.o
   ```
   
 
#### 升级回退
1. 升级
   ```
   yum upgrade bisheng-compiler
   ```
   
2. 回退
   ```
   yum downgrade bisheng-compiler
   ```
   由于毕昇编译器跨版本升级，可能发生由于文件冲突导致回退失败的情形。可以手动删除冲突文件，再尝试执行上述回退命令。
   
 
