← 返回命令列表

Linux command

clang 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Compile

clang [program.c] -o [program]

Compile

clang -O3 [program.c] -o [program]

Compile

clang -g [program.c] -o [program]

Enable

clang -Wall -Wextra [program.c] -o [program]

Compile

clang++ [program.cpp] -o [program]

说明

clang is a C, C++, and Objective-C compiler based on the LLVM compiler infrastructure. It provides fast compilation, excellent diagnostics with clear error messages, and is designed as a drop-in replacement for GCC on most platforms. Clang is known for its expressive error messages that include source highlighting, fix-it hints, and template backtrace improvements over GCC. Its modular library-based architecture enables reuse in tools like clang-format, clang-tidy, and clangd. The compiler supports modern language standards (C17, C++20, C++23), sanitizers for detecting memory errors and undefined behavior at runtime, and extensive static analysis capabilities. It is the default compiler on macOS and FreeBSD and widely used on Linux.

参数

-o _file_
Output file name
-c
Compile without linking
-g
Generate debug information
-O_level_
Optimization (0, 1, 2, 3, fast, s, z)
-std=_standard_
Language standard (c11, c17, c++17, c++20)
-Wall
Enable common warnings
-Wextra
Enable extra warnings
-Werror
Treat warnings as errors
-I _dir_
Add include directory
-L _dir_
Add library directory
-l _lib_
Link library
-fsanitize=_type_
Enable sanitizer (address, thread, memory, undefined)

FAQ

What is the clang command used for?

clang is a C, C++, and Objective-C compiler based on the LLVM compiler infrastructure. It provides fast compilation, excellent diagnostics with clear error messages, and is designed as a drop-in replacement for GCC on most platforms. Clang is known for its expressive error messages that include source highlighting, fix-it hints, and template backtrace improvements over GCC. Its modular library-based architecture enables reuse in tools like clang-format, clang-tidy, and clangd. The compiler supports modern language standards (C17, C++20, C++23), sanitizers for detecting memory errors and undefined behavior at runtime, and extensive static analysis capabilities. It is the default compiler on macOS and FreeBSD and widely used on Linux.

How do I run a basic clang example?

Run `clang [program.c] -o [program]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o _file_ do in clang?

Output file name