12. GCC compiler¶
Video introduction to this chapter:

“20-Using GCC to compile programs on Lubancat”
https://www.bilibili.com/video/BV1wc411P752/
1 2 3 4 5 | #Get warehouse
git clone https://gitee.com/LubanCat/lubancat_rk_code_storage.git
#Where the code resides
lubancat_rk_code_storage/quick_start/hello
|
In the early days, due to factors such as insufficient processor chip performance, insufficient storage space, and insufficient compilation performance, early development boards generally adopted the cross-compilation method, and the cross-compilation method has several disadvantages: offline compilation, troublesome operation, and environment configuration Complicated etc.
The processor of LubanCat-RK series has powerful performance, and the time to compile the program on the development board will be very fast, so we recommend directly using the GCC software integrated on the board to compile, which can save a lot of time on file transfer.
LubanCat-RK series comes with GCC compiler, we can use the following command to check the GCC version
1 2 3 4 5 6 7 8 9 | #View gcc command
gcc -v
#View the installation path of gcc
which gcc
#If there is no gcc, download and install
sudo apt update
sudo apt install gcc -y
|
As shown below:

The version of gcc used by the author is 9.4.0. The version number of gcc may vary due to different images and systems, but it does not affect compilation.
12.1. Hello World!¶
This tutorial will make lubancat roar with joy into the real world。
1 | quick_start/hello/hello.c
|
code:
1 2 3 4 5 6 7 8 | #include <stdio.h>
int main(void)
{
printf("Hello World!\n");
printf("meow!\n");
return 0;
}
|
source code hello.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #Use vi to create hello.c file
vi hello.c
# Type 'i' or 'a' on the keyboard to enter edit mode
#Copy the code into the vim editor
# Type the 'Esc' key on the keyboard
#Then type ":wq" to save and exit
#You can also directly download the source code to the board, and then compile it
#Enter command to compile
gcc -o hello hello.c
#execute program
./hello
|
As shown below:

lubancat let out its happy growl
12.2. vscode convenient debugging and development¶
In addition to debugging or compiling directly on the board, here we provide a more convenient method for development and debugging, which is to use vscode SSH to remotely log in to lubancat, and then perform secondary development on Lubancat.
This article is based on “SSH Login”
If SSH login cannot be realized, the following vscode remote development cannot be used normally
12.2.1. Configuration Environment¶
First, configure the environment. If you set a static IP and password-free login in the configuration environment, then in the subsequent development, you can achieve fast connection and rapid development. The development efficiency will be greatly improved.
12.2.1.1. vscode use¶
vscode download official website 《vscodeofficial website》
Vscode novice tutorial: https://blog.csdn.net/weixin_52212950/article/details/124693906
12.2.1.2. View lubancat IP address¶
1 2 | #Execute the command to view the IP
ifconfig
|
As shown below:

192.168.103.156 is the IP address of lubancat
12.2.1.3. vscode connection board¶
Before connecting the board, make sure that the network can be unblocked between the board and the host, we can open the command prompt or power shell on the PC.
1 2 3 | #ping the board
ping ip
#IP address fill in the ip address of the board
|
As shown below:

The network communication between the board and the host can be carried out normally.
Then we need to open the installed vscode, after configuring the basic operations, click the extension on the left to download the Remote-SSH plug-in.
As shown below:

After the installation is complete, you can use SSH to remotely connect to the board.
As shown below:

Then there will be content for us to fill in right above, we fill in:
1 2 3 4 5 6 | #192.168.xxx.xxxis the IP address of the board
ssh cat@192.168.xxx.xxx
#Press enter
#Then select the first save configuration
|
注意
In addition to the ssh connection directly through the ip address, we can also connect the board through the hostname. If your board and the computer are connected in the same LAN, and there is only one lubancat board in the LAN, you can use the following command to connect.
1 | ssh cat@lubancat
|
Open the board. As shown below:

Then, vscode will let you choose linux, Windows, mac, we choose Linux
If a password is required, enter it
If it is the first time to log in, vscode will ask to log in, we enter yes in the terminal

Then you can select the item you want to open by opening the folder, or others.
12.2.1.4. Password-free login¶
If you find it troublesome to log in every time you use vscode, you can use the following methods to solve it.
1 2 3 4 5 6 7 | #Open the PC's command prompt or power shell
#input
ssh-keygen -t rsa
#Then press enter continuously until the end
#Find the .ssh folder and open the id_rsa_pub file
|
As shown below:

You can open it with Notepad, and copy the contents after opening.
1 2 3 4 5 6 7 8 | #Connection board
#Log in as the cat user
#Enter on the command line
ssh-keygen -t rsa
#Then press enter continuously until the end
#You can see that there will be a .ssh folder in the /home/cat directory.
|

Then enter the folder, you can see the generated public key and private key.

1 2 3 4 | #Then we can create a file,named authorized_keys
vi authorized_keys
#Paste the content you just copied from Notepad into it, then save and exit.
|
The above is the operation without login.
Part of this article is referenced from: https://blog.csdn.net/qq_44571245/article/details/123031276
If you are confused about the operation of this article, you can refer to the above.
12.2.1.5. Connection board¶

Function introduction, as shown below:

Execute compilation and execution

The above content is a tutorial for convenient development using vscode. Similar operations are not limited to C language, C++, python, java, go, etc. can find corresponding plug-ins in vscode to assist you in development.
There are more and more functions in vscode waiting for us to discover.