Ubuntu18.04 installation and simple C language practice

Ubuntu18.04 installation and simple C language practice

Hello everyone, I will record my first installation of Ubuntu 18.04 and simple C language program compilation and running. Thanks for reading~

Installation of Ubuntu 18.04 on VMware

First, we download VMware-workstations, and then choose to create a new virtual machine on VMware, choose the Ubuntu 18.04 CD image as our operating system, allocate enough memory for Ubuntu to run normally and memory for the virtual hard disk, and then wait for the installation of Ubuntu to complete.

Insert picture description here

Download of Ubuntu-gcc compiler

Enter sudo apt install gcc in the terminal interface, and the system will automatically start downloading the gcc compiler. If the download speed is slow, you can change the download source to a domestic mirror source to download.Insert picture description here

Hello world operation

First enter touch hello.c in the terminal interface, first create a text file, then open the text file and write the hello world program in the text file. Insert picture description here
After writing, click Save and return to the terminal interface. Enter gcc hello.c -o hello to compile the program, and then enter ./ to run the program.Insert picture description here

Simple calculation program to write and run

Write a main program file main1.c and a subprogram file sub1.c, requirements: subprogram sub1.c contains an arithmetic operation function float x2x (int a, int b), this function is to input two integer parameters Perform a certain operation and return the result as a floating point number; the main program main1.c defines and assigns two integer variables, and then calls the function x2x to printf the return result of x2x. In ubuntu system, compile the main program main1.c with gcc command line and run it.
Insert picture description here

Compile and run simple programs using Makefile

First, enter make in the terminal to see if there is make in the system. If not, enter sudo apt install make to download. After the download is complete, enter gedit Makefile to create a Makefile, and enter the following content in the Makefile according to the format: Insert picture description here
Then enter make on the terminal interface to compile, and then run
Insert picture description here

Summary at the end of the article

Through the study of the above steps, you can initially master: the installation and operation of Ubuntu, the use of basic Linux commands, the compilation and operation of simple C language programs on Ubuntu, and the compilation and operation of programs in the Makefile mode.

Guess you like

Origin blog.csdn.net/m0_46145395/article/details/108773957