Embedded linux development - (1) How to write linuxC code and run it (ubantu20.04)


⏩ Hello everyone! I'm Xiaoguang, an embedded enthusiast, a sophomore who wants to become a system architect.
⏩I recently started to learn embedded linux driver development and programming. This article summarizes how to write linuxC code and makes a record.
⏩Thank you for reading, please correct me if I am wrong.


Series Article Directory


foreword

What we call writing code includes two parts: code writing and compiling. You can use Visual Studio to complete these two parts under Windows
. You can write code under Visual Studio and click compile directly.
But these two parts are separated under Linux . For example, we use VIM to write code, and then use GCC compiler to compile after
writing. There are many code writing tools, such as VIM editor, Emacs editor, VScode editor, etc. , this
tutorial uses the VIM editor that comes with Ubuntu. Let's write the simplest "Hello World" program first, and go through the C programming under Linux completely.

1. Write code

1. Open the terminal and enter the following command to create the main.c file

vi main.c

Figure 1 Create main.c
2. Enter the code in the main.c file: (if you cannot write, press i to enter the edit mode)

#include <stdio.h> 2 
int main(int argc, char *argv[])
{
    
     
    printf("Hello World!\n");
}

insert image description here
3. Press Esc to enter the command mode and enter: wq to save and exit the file
4. Enter: cat main.c to check whether the code is written successfully
insert image description here
5. Enter: gcc main.c -o main The name of the executable file compiled and generated is: main
Enter ls Check the files in the folder, there is one more main
insert image description here
6. Input: ./main to run the file, output: Hello World! Congratulations, you have succeeded!
insert image description here

Summarize

This article explains how to write a linuxC program on ubantu, and there will be more learning and practice later! ! !

Guess you like

Origin blog.csdn.net/qq_52608074/article/details/127331373