GCC Simple Getting Started manual

Source: Internet
Author: User
Keywords GCC compiler if nbsp; warning
Tags code compile compiler development development environment directory eclipse environment

This article may disappoint you if you have the following questions: Why should I command at the terminal? What is GCC, and how can it not be found in the menu? Can't GCC have a window like VC? ...... What you really want to know is probably the IDE integrated development environment such as Anjuta,kdevelop,geany,code Blocks,eclipse,netbeans. Even in this case, because GCC is the backend compiler for the IDE above, this article is still worth a little understanding.

GCC (GNU Compiler Collection,gnu Compiler Suite) is a set of programming language compilers developed by GNU. It is a set of GNU compilers set with the GPL and LGPL license issued by the http://www.aliyun.com/zixun/aggregation/29607.html "> Free software, is also a key part of the GNU program, It is also a standard compiler for the free UNIX and Mac OS X operating systems. GCC was formerly known as the GNU C language compiler because it could only handle the C language. GCC quickly expands to be able to handle C + +. It also becomes available to deal with Fortran, Pascal, C, Java, and Ada and other languages.

If you have not installed the build environment or you are not sure installed, you may wish to implement

sudo apt install build-essential

If you need to compile a Fortran program, you will also need to install Gfortran (or G77)

sudo apt install Gfortran

Compile a simple C program

The introductory example of the C language Classic is Hello world, and here is a sample code:

#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}

We assume that the code is stored as a file ' hello.c '. To compile the file with GCC, use the following command:

$ gcc-g-wall Hello.c-o Hello

This command compiles the code in the file ' hello.c ' into machine code and stores it in the executable ' hello '. The name of the machine code is specified by the-o option. This option is usually the last parameter on the command line. If omitted, the output file defaults to ' A.out '. Note that if a file with the same name as the executable file already exists in the current directory, it will be overwritten.

Option-wall turn on almost all of the compiler's usual warnings--it is strongly recommended that you always use this option. The compiler has many other warning options, but-wall is the most common. By default, GCC does not generate any warning messages. Compiler warnings are very helpful when writing C or C + + programs to detect problems with your program. 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

In this case, the compiler uses the-wall option without warning because the sample program is completely legal.

The option ""-g "indicates that with debug information in the generated destination file, debugging information can help you analyze the source of the error, including very useful information, such as the file name and line number that produced the error, after the program has aborted the core.

To run the program, enter the path to the executable file as follows:

$/hello
Hello, world!.

This loads the executable file into memory and causes the CPU to start executing the instructions it contains. Path./refers to the current directory, so./hello loads and executes the executable file ' Hello ' in the current directory.

Click here (Http://ubuntu:ubuntuftp@ftp.ubuntu.org.cn/home/dbzhang800/wiki/gcchowto1.avi) to download the action video for this section

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.