2.2. 编译源文件

使用 Clang 编译器编译源文件以及编译语言源文件。clang 创建一个可执行文件,从而进行编译。为了调试代码,请通过在 Clang 命令中添加 -g 标志来启用调试信息。

注意

要编译 C++ 程序,请使用 clang++ 而不是 clang

流程

要编译您的程序,请运行以下命令:

  • 在 Red Hat Enterprise Linux 7 上:

    $ scl enable llvm-toolset-15.0 'clang -o -g <binary_file> <source_file>'
    • <binary_file > 替换为输出文件所需的名称,<source_file > 替换为您的源文件的名称。
  • 在 Red Hat Enterprise Linux 8 中:

    $ clang -o -g <binary_file> <source_file>
    • <binary_file > 替换为输出文件所需的名称,<source_file > 替换为您的源文件的名称。
  • 在 Red Hat Enterprise Linux 9 中:

    $ clang -o -g <binary_file> <source_file>
    • <binary_file > 替换为输出文件所需的名称,<source_file > 替换为您的源文件的名称。