How to compile and run C programs under Linux

Source: Internet
Author: User

GCC is a very important source code compilation tool under the Linux operating system and has many important options to support the compilation of many different languages, such as C, C + +, Ada, Fortran, Objective, Perl, Python, Ruby and Java, etc. Even Linux's many kernels and many other free software and open source applications are written in C and compiled by GCC.

1. Compiling a single source file

[For example] print "Hello,linux." On the screen.

[Source code]

#include <stdio.h>

#include <stdlib.h>

int main (int argc,char **argv)

{

printf ("hello,linux.\n");

Exit (0);

}

Save the source file as hello.c and start compiling

$GCC-O Hello hello.c

After the compilation completes successfully, under the current path, generate a file named Hello, and then execute

$./hello

On the screen, you will see the results of the printing: Hello,linux.

Note: By default, after the compilation completes successfully, a file named A.out is generated under the current path, and then the $./a.out can be printed, but you can usually specify your own executable name by using the option-O.

How 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.