Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a cross-compilation environment for raspberry pie

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to build a cross-compilation environment for raspberry pie. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Host: CentOS 7 64bit

Target hardware platform: raspberry Pi 2B+

GPIO operation library: wiringPi

Host working home directory: / home/xxxxx/raspberryPi

Forget about the installation of git.

Enter the working home directory

1. Download the official raspberry cross-compilation tool

Git clone git://github.com/raspberrypi/tools.git

Enter the tools/arm-bcm2708/ directory

For a 32-bit system, use gcc-linaro-arm-linux-gnueabihf-raspbian/bin

If it is a 64-bit system, use gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin (this example)

Add it to the environment variable:

Sudo nano ~ / .bashrc (~ represents home directory)

Put export PATH=$PATH:$HOME/raspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

Add to the end of the file and save exit

Use source ~ / .bashrc to make it effective, or log out / restart

In any directory: type arm-linux-gnueabihf-gcc-v if you can find the compiler, indicate OK

Return to the working home directory

2, download wiringPi (http://wiringpi.com/download-and-install/)

Git clone git://git.drogon.net/wiringPi

Download on the host machine in order to use its header file, so do not enter the directory. / build

3. Download your own development directory, according to your own situation

Git clone https://git.oschina.net/xxxxx.git

On the target hardware platform

Download wiringPi to a directory as above, and then enter the directory here. / build

In this way, libwiringPiDev.so.2.25 and libwiringPi.so.2.25 will be generated under the / usr/local/lib directory (the version number is different from the lib directory location, so you can find it first)

In some way, copy these lib to the host working directory. For example, copy to / home/xxxxx/raspberryPi/rpi2Dev/wiringPi_Lib directory

On the host, go to the / home/xxxxx/raspberryPi/rpi2Dev/wiringPi_Lib directory

Create a soft connection with no version number:

Ln-s libwiringPi.so.2.25 libwiringPi.so

Ln-s libwiringPiDev.so.2.25 libwiringPiDev.so

If the source file is to reference this lib library, then in makefile-L/xxxx/xxxx-lwiringPi, specify the location of the lib

At the same time, makefile also specifies the location of the included file, and-I specifies to the wiringPi directory

Refer to the makefile and the source file at the end.

Note: in theory, third-party libraries can be cross-compiled on the host machine, and should do so.

But I opened wiringPi's build and looked for it in its directory. There is no such thing as configure that specifies the tool chain.

Maybe I don't understand, but it's not done. If anyone knows how to do it, say it and share it.

Once all this is done, you can code and compile, and there are many ways to upload the compiled bin to the raspberry pie.

Tell me about my method.

Because I have done the development of network programs on centos, I have installed nginx.

Then I will softly connect the directory where I generated bin to the web directory of nginx

In this way, on the raspberry pie side, you can download the executable file using tools such as curl. It's very convenient.

It's easy to write a download and execute a script on a raspberry pie.

# make file of raspberri pi CrossCC=arm-linux-gnueabihf-gcc LD=$ (CC) TARGET=helloOBJECT=hello.o RASPBERRY_PI_DIR=/home/xxxxx/raspberryPiWIRING_PI_INCLUDE_PATH=$ (RASPBERRY_PI_DIR) / wiringPi/wiringPi# this lib is first generated on the target platform WIRING_PI_LIB_PATH=$ (RASPBERRY_PI_DIR) / rpi2Dev/wiringPi_Lib$ (TARGET): $(OBJECT) $(LD)-o $(TARGET) $(OBJECT)-L$ (WIRING_PI_LIB_PATH)-lwiringPihello. O:hello.c $(CC)-o hello.o-c hello.c-I $(WIRING_PI_INCLUDE_PATH) clean: rm-f $(TARGET) $(OBJECT) install: # sudo cp / home/xxxx/pi/bin/hello hello # cp-f $(TARGET) / usr/bin Chmod-R 777 / usr/bin/pushServer#include # include int main (void) {int bright; printf ("System start...\ n"); if (wiringPiSetup () =-1) exit (1); pinMode (1, PWM_OUTPUT); while (1) {for (bright = 0; bright)

< 1024 ; ++bright) { pwmWrite (1, bright) ; delay (1) ; } for (bright = 1023 ; bright >

= 0;-- bright) {pwmWrite (1, bright); delay (1);}} return 0 } this is the end of the article on "how to build a cross-compilation environment for raspberry pie". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report