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.
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.
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.
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.
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.
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:
Then enter make on the terminal interface to compile, and then run
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.