Using GCC to compile and run C programs under Linux

Source: Internet
Author: User

GCC (GNU Compiler Collection) is the most commonly used C language compiler under Linux and is a compiled system conforming to the ANSI C standard in the GNU project, capable of compiling programs written in C, C + +, and object C.

There are two common ways to use Linux systems, as follows:

Gcc-o out       in1    in2                          //gcc Compile and link (compile and build in2 file for in1 and Out.bin files, "-O": Represents the build executable file)-C out       in1    in2                         //  GCC compilation is not linked (in1 files and in2 file files are compiled to generate OUT.O files, "-C": Indicates that only *.O files are generated)

In the ARM Development Board, you need to use ARM-LINUX-GCC cross-compiling:

Arm-linux-gcc-o out       in1    in2                          //gcc Compile and link (compile and build in2 file for in1 and Out.bin files, "-O" : Represents the build executable file)arm-linux-gcc-c out       in1    in2                         //  GCC compilation is not linked (in1 files and in2 file files are compiled to generate OUT.O files, "-C": Indicates that only *.O files are generated)

To compile two programs A.C and hello.c as an example:

VI a.c //Edit A.C, it will be called by HELLO.C, provided that the two files must be in the same directory

The contents are as follows:

VI hello.c //Edit hello.c

The contents are as follows:

gcc-o Hello hello.c a.c //gcc compile and link (compile the hello.c file and a.c file to generate Hello.bin file, "-O": Represents the build executable file)

./hello //Run Hello.bin

The effect is as follows:

Using GCC to compile and run C programs under Linux

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.