My build host is Ubuntu 24.04.My target is a Raspberry Pi Zero 2 w.
I was able to follow the cross compile instructions at https://www.raspberrypi.com/documentati ... ernel.html and they worked great. I was able to build the kernel from source and boot from it just fine.
On the target RPI Zero 2 w I was able to compile and run this program just fine.
```
$ g++ main.cpp
chrisk@sws:~ $ ./a.out
Starting
sht4x temperature unavailable
sht4x humidity unavailable
^C
```
But I want to build it on my build host. So, I need to cross-compile it. My understanding is to cross compile you want to use the same headers and libraries on the build host as on the target host. So, I mounted the SD card which mounted the rootfs partition to /media/chrisk/rootfs, on my build host and did the following on the build host
```
$ mkdir -p /opt/sdk/rpi_zero_2_w
$ cd /media/chrisk/rootfs
$ tar -cf - lib usr/lib usr/include | tar -C /opt/sdk/rpi_zero_2_w -xf -
```
So, that now I have a copy of the /usr/include and /usr/lib on my build host at /opt/sdk/rpi_zero_2_w. Then on the build host I ran the g++ cross compiler that was used when building the kernel using the --sysroot option.It completed successfully and I scp'ed it to the target host.
```
$ aarch64-linux-gnu-g++ --sysroot=/opt/sdk/rpi_zero_2_w main.cpp
$ scp a.out sws.local:a.out
chrisk@sws.local's password:
a.out 100% 73KB 487.0KB/s 00:00
```
When I run it I get this error
```
$ ./a.out
./a.out: /lib/aarch64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by ./a.out)
```
I am not sure where things are wrong or what else to try. I found where running the cross compiler with -v and verify the cross compiler has the sysroot option. It seems that it does:
```
4 aarch64-linux-gnu-g++ -v
<bunch o stuff>
--with-sysroot=/
<more stuff>
```
Having --sysroot=/ on that output is supposed to indicate that the cross compiler supports the --sysroot option.
Any pointers or suggestion would be appreciated.
Thanks
Chris
I was able to follow the cross compile instructions at https://www.raspberrypi.com/documentati ... ernel.html and they worked great. I was able to build the kernel from source and boot from it just fine.
On the target RPI Zero 2 w I was able to compile and run this program just fine.
```
$ g++ main.cpp
chrisk@sws:~ $ ./a.out
Starting
sht4x temperature unavailable
sht4x humidity unavailable
^C
```
But I want to build it on my build host. So, I need to cross-compile it. My understanding is to cross compile you want to use the same headers and libraries on the build host as on the target host. So, I mounted the SD card which mounted the rootfs partition to /media/chrisk/rootfs, on my build host and did the following on the build host
```
$ mkdir -p /opt/sdk/rpi_zero_2_w
$ cd /media/chrisk/rootfs
$ tar -cf - lib usr/lib usr/include | tar -C /opt/sdk/rpi_zero_2_w -xf -
```
So, that now I have a copy of the /usr/include and /usr/lib on my build host at /opt/sdk/rpi_zero_2_w. Then on the build host I ran the g++ cross compiler that was used when building the kernel using the --sysroot option.It completed successfully and I scp'ed it to the target host.
```
$ aarch64-linux-gnu-g++ --sysroot=/opt/sdk/rpi_zero_2_w main.cpp
$ scp a.out sws.local:a.out
chrisk@sws.local's password:
a.out 100% 73KB 487.0KB/s 00:00
```
When I run it I get this error
```
$ ./a.out
./a.out: /lib/aarch64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by ./a.out)
```
I am not sure where things are wrong or what else to try. I found where running the cross compiler with -v and verify the cross compiler has the sysroot option. It seems that it does:
```
4 aarch64-linux-gnu-g++ -v
<bunch o stuff>
--with-sysroot=/
<more stuff>
```
Having --sysroot=/ on that output is supposed to indicate that the cross compiler supports the --sysroot option.
Any pointers or suggestion would be appreciated.
Thanks
Chris
Statistics: Posted by chriskot870 — Tue Sep 03, 2024 8:33 pm — Replies 0 — Views 25