Compile the C ++/C file using the command line

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.