红穆笔记

clang++

编译 C++ 源文件。 LLVM 项目的组件之�

100% 浏览器本地处理 0 数据上传

常用示例

将一组源文件编译为二进制文件

clang++ {{源/文件/的路径1.cpp 源/文件/的路径2.cpp ...}} {{[-o|--output]}} {{可执行/文件/的路径}}

打印所有错误和警告

clang++ {{源/文件/的路径.cpp}} -Wall {{[-o|--output]}} {{可执行文件}}

打印普通警告和调试信息, 并在不影响调试的情况下优化

clang++ {{源/文件/的路径.cpp}} -Wall {{[-g|--debug]}} -Og {{[-o|--output]}} {{可执行/文件/的路径}}

指定 C++ 语言标准

clang++ {{源/文件/的路径.cpp}} -std={{c++20}} {{[-o|--output]}} {{可执行/文件/的路径}}

包含与源文件不在同一路径下的库

clang++ {{源/文件/的路径.cpp}} {{[-o|--output]}} {{可执行/文件/的路径}} -I{{头/文件/的目录}} -L{{库/的目录}} -l{{库的名字}}

将源文件编译为 LLVM 中间表示(IR)

clang++ {{[-S|--assemble]}} -emit-llvm {{源/文件/的路径.cpp}} {{[-o|--output]}} {{IR/的/路径.ll}}

优化编译后程序的性能

clang++ {{源/文件/的路径.cpp}} -O{{1|2|3|fast}} {{[-o|--output]}} {{可执行/文件/的路径}}

打印版本信息

clang++ --version

提示:花括号{{…}}是需要替换的参数(路径、文件名等);命令只在本机终端执行,本站不保存任何输入。

英文原文对照

展开英文说明与示例(来源 tldr-pages)

Compile C++ source files. Part of LLVM. More information

Compile a set of source code files into an executable binary

clang++ {{path/to/source1.cpp path/to/source2.cpp ...}} {{[-o|--output]}} {{path/to/output_executable}}

Activate output of all errors and warnings

clang++ {{path/to/source.cpp}} -Wall {{[-o|--output]}} {{output_executable}}

Show common warnings, debug symbols in output, and optimize without affecting debugging

clang++ {{path/to/source.cpp}} -Wall {{[-g|--debug]}} -Og {{[-o|--output]}} {{path/to/output_executable}}

Choose a language standard to compile for

clang++ {{path/to/source.cpp}} -std={{c++20}} {{[-o|--output]}} {{path/to/output_executable}}

Include libraries located at a different path than the source file

clang++ {{path/to/source.cpp}} {{[-o|--output]}} {{path/to/output_executable}} -I{{path/to/header_path}} -L{{path/to/library_path}} -l{{path/to/library_name}}

Compile source code into LLVM Intermediate Representation (IR)

clang++ {{[-S|--assemble]}} -emit-llvm {{path/to/source.cpp}} {{[-o|--output]}} {{path/to/output.ll}}

Optimize the compiled program for performance

clang++ {{path/to/source.cpp}} -O{{1|2|3|fast}} {{[-o|--output]}} {{path/to/output_executable}}

Display version

clang++ --version

命令信息

命令名clang++
用途编译 C++ 源文件。 LLVM 项目的组件之�
适用平台通用
示例数量8 条
官方文档https://clang.llvm.org/docs/UsersManual.html#command-line-options
数据来源tldr-pages(CC-BY-4.0)· 社区中文翻译

常见问题

clang++ 命令是做什么的?

编译 C++ 源文件。 LLVM 项目的组件之�

clang++ 怎么用?

页面按场景列出了8 条常用示例:每条示例先说明用途,再给出可直接复制的完整命令(花括号里是需要替换的参数)。

clang++ 最常用的操作是什么?

将一组源文件编译为二进制文件:clang++ {{源/文件/的路径1.cpp 源/文件/的路径2.cpp ...}} {{[-o|--output]}} {{可执行/文件/的路径}}

命令里的花括号是什么意思?

花括号{{…}}表示需要替换成你自己的值,例如路径、文件名;同名参数方括号(如 [-C|--directory])表示可选写法。