Run a C language program compiled on Debain on a Raspberry Pi Zero.
I want to create an environment where I can use shared libraries.
For the time being, let's use libusb
or libjpeg
.
Continuing from Starting cross-compilation for Raspberry Pi Zero on Ubuntu, I am trying again with Debian as the host machine (for a reason later).
Host: Debian 10.6.0 <Virtual Box 6.1 <WIndows10 Target: Raspberry Pi Zero WH
$ sudo apt install crossbuild-essential-armel
Last time tried installing g ++-arm-linux-gnueabi
, but it seems to be included in crossbuild-essential-armel
So I will install this. After all, gcc is used, so it doesn't make much difference.
Add architecture,
$ sudo dpkg --add-architecture armel
Editing sources.list
. I will add the repository referenced by apt
.
$ sudo nano /etc/apt/sources.list
Add the following at the bottom of sources.list
.
For armel, also refer to ftp.jp.debian.org.
/etc/apt/sources.list
deb [arch=armel] http://ftp.jp.debian.org/debian buster main
Update and install the library.
You can get the library for armel
by adding: armel
.
$ sudo apt update
$ sudo apt install libusb-dev:armel
$ sudo apt install libjpeg-dev:armel
Maybe if the package is published for Ubuntu armel, I think I can do the same with Ubuntu by adding it to sources.list
, but I found that I published the armel package for Ubuntu not.
試しにUbuntuでftp.jp.debian.org/debianを追加してみましたが、「署名されてません」みたいなエラーが出てインストールできませんでした。そりゃそうか。
Is there a way to forcefully install it? (I was able to bring in .deb and install it, but I gave up because the dependency became difficult)
Click here for the program to build this time.
testUsbLib.c
#include <stdio.h>
#include <usb.h>
int main()
{
printf("call usb_init()\n");
usb_init();
printf("OK\n");
return 0;
}
A useless program that just calls usb_init ()
.
It doesn't clean up usb_init ()
(did I have to do something ...?).
Build here.
$ arm-linux-gnueabi-gcc -march=armv6 testUsbLib.c -o testUsbLib_armv6 -lusb
If you can build successfully above, copy the generated testUsbLib_armv6
to a suitable folder on Raspberry Pi Zero,
$ testUsbLib_armv6
call usb_init()
OK
And it works like this. Nothing happens, but ...
Since libusb
has few dependencies, it can be quite good even if you get the .deb file and install it manually, but libjpeg
etc. have many dependencies, and I gave up because there were too many steps manually. This method installed it including the dependencies, so it seems to have worked.
By the way, I have confirmed the operation of libtiff
in addition to libusb
and libjpeg
by this method.
Also, if anyone knows if the same method can be used on Ubuntu (whether there is a package for armel published, etc.), please let me know.
I wrote the following article.
Recommended Posts