LTS

    Innovation Version

      Using LLVM/Clang for Compilation

      This chapter describes the basic knowledge of LLVM/Clang compilation and provides examples for demonstration. For more information about how to use Clang, run the clang --help command.

      Overview

      LLVM is a compiler that covers multiple programming languages and target processors. It uses Clang as the compiler and driver of C and C++. Clang can not only compile C and C++ programs into the LLVM intermediate representations (IRs), but also invoke all LLVM optimization passes for code generation until the final binary file is generated.

      LLVM/Clang Installation

      Install the Clang and LLVM software packages using the Yum source in the openEuler OS. llvm12 is installed by default.

      yum install llvm
      yum install clang
      yum install lld // The openEuler Yum source does not contain LLD12.
      

      Check whether the installation is successful.

      clang -v
      

      If the command output contains the Clang version information, the installation is successful.

      Coexistence of Multiple Versions

      Configure the openEuler LLVM/Clang multi-version support as follows:

      Yum package name:
      llvm<ver>{-*}
      clang<ver>{-*}
      lld<ver>{-*}
      bolt<ver>{-*}
      Example:
      clang15
      llvm15-devel
      
      Installation path:
      /usr/lib64/llvm<ver>
      Example:
      /usr/lib64/llvm15
      
      Executable files with the -<ver> suffix are installed in the /usr/bin directory.
      Example:
      /usr/bin/clang-15
      /usr/bin/lld-15
      

      Currently, the following LLVM/Clang versions are supported:

      llvm //By default, llvm12 is installed.
      llvm-15
      

      Install other versions using Yum.

      yum install llvm15
      yum install clang15
      yum install lld15
      

      Check whether the installation is successful.

      clang-15 -v
      

      Example

      Compile and run C and C++ programs.

      clang  [command line flags]  hello.c  -o  hello.o 
      ./hello.o
      
      clang++  [command line flags]  hello.cpp  -o  hello.o 
      ./hello.o
      

      Specify the LLD of LLVM as the linker. If it is not specified, the default LLD is used.

      clang  [command line flags]  -fuse-ld=lld  hello.c  -o  hello.o 
      ./hello.o
      

      For more information, see the LLVM User Guides.

      Bug Catching

      Buggy Content

      Bug Description

      Submit As Issue

      It's a little complicated....

      I'd like to ask someone.

      PR

      Just a small problem.

      I can fix it online!

      Bug Type
      Specifications and Common Mistakes

      ● Misspellings or punctuation mistakes;

      ● Incorrect links, empty cells, or wrong formats;

      ● Chinese characters in English context;

      ● Minor inconsistencies between the UI and descriptions;

      ● Low writing fluency that does not affect understanding;

      ● Incorrect version numbers, including software package names and version numbers on the UI.

      Usability

      ● Incorrect or missing key steps;

      ● Missing prerequisites or precautions;

      ● Ambiguous figures, tables, or texts;

      ● Unclear logic, such as missing classifications, items, and steps.

      Correctness

      ● Technical principles, function descriptions, or specifications inconsistent with those of the software;

      ● Incorrect schematic or architecture diagrams;

      ● Incorrect commands or command parameters;

      ● Incorrect code;

      ● Commands inconsistent with the functions;

      ● Wrong screenshots.

      Risk Warnings

      ● Lack of risk warnings for operations that may damage the system or important data.

      Content Compliance

      ● Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions;

      ● Copyright infringement.

      How satisfied are you with this document

      Not satisfied at all
      Very satisfied
      Submit
      Click to create an issue. An issue template will be automatically generated based on your feedback.
      Bug Catching
      编组 3备份