Compile the c file using gcc Compile C ++ files (including. C/C ++ files) with G ++
Let's take a look at the common methods for compiling C ++ files:
Single file:
G ++ file. cpp
This is the simplest form. The default output is a. Out. You can use the-O command to specify the output file, such as G ++ file. cpp F. Out.
Multiple files:
G ++-C 1.cpp-O 1.o
G ++-C 2.cpp-O 2.o
G ++ 1.o 2.o-O Prog. Out
Link to an executable file:
Generally, G ++-o file. cpp is used.
Multiple files are g ++-o file file1.cpp file2.cpp...
Compile C ++ instead of using gcc but G ++.
If GCC can be compiled but cannot be linked.
Multiple files:
1. Compile multiple files without connection:
G ++ file1.cpp file2.cpp
Two files are generated: file1.o and file2.o.
2. Connection:
G ++-O outfilename file1.o file2.o
An executable file named outfilename is generated.
If you want to complete compilation and connection in one step, then:
G ++-O outfilename file1.cpp file2.cpp
-O option controls whether to connect.