C & amp; Cpp Program Development in Linux (1), Linux

Source: Internet
Author: User

C & Cpp Program Development in Linux (1), Linux

I have been designing programs in Windows. I recently started to learn how to use Linux, so I plan to transfer program development to Linux. Today, I will briefly introduce the C program development steps under the system.

First, install the vim and gcc tools in advance, and then compile a "Hello World" program:

1. Open the command window in the directory, enter vim hello. c to create and open the hello. c file, press <I> to enter the editing mode, and enter the following code:

1 #include<stdio.h>2 3 int main()4 {5     printf("Hello World!\n");6     return 0;7 }

Press <Esc> to exit editing. <:> wq: Save and exit the editing page.

2. Input gcc hello. c-o hello to compile the hello. c file and output the hello executable file. It means: gcc [source file name] outputs [output file name]. You can also perform step-by-step compilation.

Gcc-E hello. c-o hello. I pre-compiled

Gcc-S hello. I-o hello. s compiles the generated hello. I file to generate assembly code.

Gcc-c hello. s-o hello. o compiles the assembly code file hello. s into the target file.

Gcc hello. o-o hello connects hello. o to the C standard input and output library, and finally generates the program hello

3. Enter./hello to run the hello program in the current directory. The "Hello World!" printed on the screen will be displayed !" .

Now that the Hello World Program has been compiled, I will introduce the compilation of multiple files. Create Main. c and Add. c files

1 /*2 Add.c3 */4 #include<stdio.h>5 6 int add(int num0,int num1)7 {8     return num0+num1;9 }

 

 1 /* 2 Main.c 3 */ 4 #include<stdio.h> 5  6 int add(int num0,int num1); 7   8 int main() 9 {10     printf("%d",add(1,2));11     return 0;12 }

After writing two files, enter gcc Main. c Add. c-o ADD in the command line. Enter./ADD to run the program.

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.