Compile C language programs using gcc in Linux

Source: Internet
Author: User

GCC is the most widely used tool for compiling C and C ++ languages in Linux. Unlike C and Java, generating an executable file is divided into two parts: Compilation and connection. Let's take a brief look.

For example, to compile a Test. c Application, compile the code first. The command is as follows:

Gcc-c Test. c

We will find that a file named Test is generated in the current directory. o binary file. This file is the product of compilation, but it cannot be run directly. It must be linked with the external lib before the executable file can be generated. The command is as follows:

Gcc-o Test. o

After the execution is complete, you will find that an executable file a. out is generated in the current directory and can be run using the./a. out command.

In addition, Linux C can use gcc to compile a dynamic Runtime Library, just like a dll in Windows, which can separate static coupling between lib and the execution program and facilitate program upgrade. Yes

Gcc-shared-o a. so Test. o

After the execution, you will find that the current directory generates a dynamic Runtime Library named a. so.

Of course, you can combine the compilation and link into one, for example, through

Gcc Test. c

After the command, you can directly generate a. out, suitable for use in simple programs without external lib.

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.