Перейти к основному содержимому

12. GCC compiler

12.1 Use armsom's built-in compile chain to compile code

The armsom file system has its own compile chain. When compiling source code, you can directly use the built-in compile chain in the board to compile source code, which is convenient for users to develop directly.

To check whether the built-in compile chain exists, you can use the following command:

gcc -v

image

The gcc version varies with the armbian version. For sige5, the author currently uses the latest armbian image, whose gcc version is 13.2.0. The difference between gcc versions is not large, which does not affect the execution effect of the final compiled executable file.

Then we compile a simple routine to test whether the compile chain is available.

# Enter the following command in the ~ path. This command will use nano to create an armsom.c file
nano armsom.c

Paste the following code in the newly created terminal:

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

After that, we press the ctrl and x keys on the keyboard at the same time, and we will be asked whether to save the content we just modified. We press y on the keyboard. At this time, we are still in the newly created terminal. We press Enter again. At this time, we return to the ~ directory

After that, we use gcc to compile the hello armsom source code we just wrote. Enter the following command in the serial terminal:

gcc armsom.c -o armsom

The terminal prints the following information to indicate that the compilation chain is available.

image

12.2.1 Install vscode and required plug-ins

vscode download official website 《vscode official website》

vscode beginner tutorial: https://blog.csdn.net/weixin_52212950/article/details/124693906

‍ Install the following plug-ins in vscode.

image

image

Enter the username@ip above

The username is armsom, and the ip needs to be obtained through the ip a command

image

Then click

image

Then enter the password in the new pop-up dialog box to log in.

image

If the password is correct, you can directly enter the board file system.

image

Here we can see the armsom.c routine we wrote before.

image

If you find it troublesome to enter the password every time, you can choose to use the following method to create an ssh key login.

12.2.2 Create a key for password-free login

If you find it troublesome to log in every time when using vscode, you can use the following method to solve it

PC side:

# Search cmd in the PC search box, then select Enter and enter the following command
ssh-keygen -t rsa

#Then press Enter continuously until the end

#Find the .ssh folder, usually in My Computer->C Drive->User->.ssh/ Open the id_rsa_pub file in the .ssh folder and copy the content. The general format is
ssh-ed25519 xxxyyyzzz

armsom board side:

# Execute the following command
ssh-keygen -t rsa

# Enter .ssh
cd ~/.ssh

# Create authorized_keys
nano authorized_keys

# Copy the ssh-ed25519 xxxyyyzzz copied in the PC Write to this file

image

Now repeat the above process of using vscode to connect to the board using ssh. You no longer need to enter a password.