C Compilation Preliminary

Source: Internet
Author: User
Keywords nbsp; compiling GCC source code executable
Tags aliyun archive code command line compile compiling default file

C Programming related file suffix

. a&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP; Static Library (archive)
. C C Source code (requires compilation preprocessing)
. h C Source Dock files
. I c source code (no compilation preprocessing required)
. O Object File
. S assembly Language Code
. So dynamic Library

A single source file generates an executable program

Here is a simple "Hello, ubuntu" program source code:

/* HELLOUBUNTU.C *
#include <stdio.h>
int main (int argc,char *argv[])
{
printf ("Hello, ubuntu\n");

return 0;
}

The simplest way to compile the code as an executable is to save the code as a file helloubuntu.c and execute the following command:

$ Gcc-wall HELLOUBUNTU.C

The compiler recognizes a C source code file by checking the suffix name of the file specified on the command line. GCC Default action: Compile source code file to generate object file, link object file get executable program, delete object file. The compiler takes the default a.out because the file name of the executable program is not specified on the command line. Enter a program name on the command line to perform and display the results:

$/a.out
Hello, Ubuntu

Option-O is used to specify the file name of the generated executable program. The following command generates an executable program named Helloubuntu:

$ gcc-wall Helloubuntu.c-o Helloubuntu

Enter the program name on the command line to execute it as follows:

$/helloubuntu
Hello, Ubuntu

Note Use the LM parameter if it is useful to a standard library, such as the MATH.H library, that is not a default call for GCC

Source file Generation Object file

Option-C instructs GCC to compile the source code file, but keep the object file on disk and skip the link object file to generate the executable file. In this case, the default output file's filename is the same as the code file name, except that the suffix is changed to. O. For example, the following command generates an object file named HELLOUBUNTU.O:

$ gcc-c-wall helloubuntu.c

Option-O can be used to specify the file name of the generated object file. The following command produces an object file named KUBUNTU.O:

$ gcc-c-wall Helloubuntu.c-o KUBUNTU.O

When building object libraries or generating a series of object files for later links, a command can generate the corresponding object files from multiple source files. The following command generates object files UBUNTU.O, KUBUNTU.O, and XUBUNTU.O:

$ gcc-c-wall ubuntu.c kubuntu.c xubuntu.c

Related Article

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.