← 返回命令列表

Linux command

g++ 命令

文本

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

常用示例

Compile C++ file

g++ [source.cpp] -o [output]

Compile with warnings

g++ -Wall -Wextra [source.cpp] -o [output]

Compile with optimization

g++ -O2 [source.cpp] -o [output]

Debug build

g++ -g [source.cpp] -o [output]

Compile with C++

g++ -std=c++17 [source.cpp] -o [output]

说明

g++ is the GNU C++ compiler, part of the GNU Compiler Collection. It compiles C++ source code to executables or object files, supporting modern C++ standards. The compiler handles preprocessing, compilation, assembly, and linking. It provides extensive optimization options and warning controls for quality code production. g++ is the standard C++ compiler on Linux systems, supporting the full range of C++ language features.

参数

-o _FILE_
Output filename.
-c
Compile only, no linking.
-Wall
Enable common warnings.
-Wextra
Enable additional warnings beyond -Wall.
-g
Generate debug info.
-O _LEVEL_
Optimization level (0-3, s, fast).
-std=_STANDARD_
C++ standard (c++11, c++14, c++17, c++20, c++23).
-I _PATH_
Include path.
-L _PATH_
Library path.
-l _LIBRARY_
Link library.
--help
Display help information.

FAQ

What is the g++ command used for?

g++ is the GNU C++ compiler, part of the GNU Compiler Collection. It compiles C++ source code to executables or object files, supporting modern C++ standards. The compiler handles preprocessing, compilation, assembly, and linking. It provides extensive optimization options and warning controls for quality code production. g++ is the standard C++ compiler on Linux systems, supporting the full range of C++ language features.

How do I run a basic g++ example?

Run `g++ [source.cpp] -o [output]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o _FILE_ do in g++?

Output filename.