Cross-compilation wiringPi library, [Allwinner H616, orangepi-zero2]

Book from last chapter

Last time, Quanzhi's gcc cross-compilation tool was completely installed
https://blog.csdn.net/qq_52749711/article/details/132306764

wiringPi full library download

Download link
First get your own development board and unzip it directly

unzip wiringOP-master.zip

After unzipping, enter the directory, find the location of the build file
and run it directly

./build

Then the installation is completed directly and you can use

Then follow the same steps to get it on your own virtual machine.

Note that after the virtual machine enters ./build, a pop-up will pop up asking you to select the installation option.
After that, the following box will pop up
Insert image description here
. It is reasonable to install 25 or 26. I entered 26 (I was blind and wrong, but it is actually possible. There are experts who can Tell me what the hell 26 is)

After installation, it is not possible to directly run the corresponding program with the wiringPi library. An error will be reported directly.
Why? (A lot of detours have been taken, summary)
Because even if the corresponding model is selected, its internal compilation does not use the cross-compilation gcc we installed last time, but uses the gcc of the virtual machine. As a result, the libraries that come out are all under the x86 platform. of. Therefore, you need to copy the libraries of the virtual machine to the virtual machine again.
Required libraries:
Insert image description here
Insert image description here
These two libraries are in the wiringPi installation directory of the development board, the wiringPi directory and the devLib directory. Use the scp command to test them out.

scp libwiringPi.so.2.46 shunge@192.168.10.31:/home/shunge
scp libwiringPiDev.so.2.46 shunge@192.168.10.31:/home/shunge

After success, you need to create a link to facilitate the calling of the library. If you want to call the library, you will not need to add a bunch of version information~

Create soft link

Here are two types of links:

Soft connection

Have you seen Windows shortcuts? Yes, Linux soft links are similar to shortcuts. After they are created, a file image is generated at the location you choose. It does not take up disk space. This file contains the location information of the real file, etc. wait

Soft link creation

//指令 参数   要被链接的文件    软链接文件名字
 ln -s libwiringPi.so.2.46 libwiringPi.so

-s means symbolic link

hard link

It will generate a file with the same size as the source file in the location you selected.

Hard link creation

Just don’t add parameter -s

ln libwiringPi.so.2.46 libwiringPi.so

What would you choose after watching it?

Decisive soft connection
input command

 ln -s libwiringPi.so.2.46 libwiringPi.so
 ln -s libwiringPiDev.so.2.46 libwiringPiDev.so

So you can compile the .c file with the wiringPi library

test

A servo program I wrote before is just for experiment. (I won’t read the code here, I mainly explain the compilation process)

Write build.sh to facilitate direct compilation later.

aarch64-none-linux-gnu-gcc $1 -I ./wiringOP-master/wiringPi -L. -lwiringPi -lwiringPiDev -lpthread -lm -lcrypt -lrt -g -o $2

Use build.sh to compile the .c file with the wiringPi library

./build.sh servo.c servo

Insert image description here
No error message is reported, and a servo file is generated in the current directory.
Use file to view file information.
Insert image description here
Perfect, ARM, not x86
using spc to upload to Raspberry Pi

scp servo orangepi@192.168.10.25:/home/orangepi/test

Insert image description here

Raspberry Pi runs servo file

Insert image description here

Finish

If you encounter any problems, you are welcome to raise them and make progress together.

Guess you like

Origin blog.csdn.net/qq_52749711/article/details/132329698