Introduction
This is the chapter web page to support the content in Chapter 7 of the book: Exploring Raspberry Pi – Interfacing to the Real World with Embedded Linux. The summary introduction to the chapter is as follows:
To this point in the book, all the code is built and executed directly on the RPi. However, for larger projects this can be impractical, because you may need to manage many source fi les within a single project. In addition, compilation times can be slow on the RPi for building large projects. This chapter first describes how you can use your desktop computer to develop applications that can be deployed directly to the RPi. The Eclipse integrated development environment (IDE) is then introduced, which allows for advanced development capabilities, such as remote debugging. The chapter finishes by outlining how you can build and deploy a custom Linux kernel for the RPi platform.
Learning Outcomes
After completing this chapter, you should be able to:
- Install a cross-compilation toolchain on desktop Linux that can be used to build applications for the RPi using your desktop PC.
- Use a package manager to install multi-architecture third-party libraries that may be required for cross-compilation.
- Emulate the ARM architecture on the desktop PC using QEMU.
- Install and configure the Eclipse integrated development environment (IDE) for cross-compilation to build RPi applications.
- Configure Eclipse for remote deployment of applications, remote debugging, GitHub integration, and automated documentation.
- Build a custom Linux kernel and deploy it to the RPi.
The screen capture below is a full resolution capture of the final steps in the installation of the Eclipse IDE remote debug environment for cross-compilation to the Raspberry Pi.
Digital Media Resources
While the video below was created for the BeagleBone platform, the content in the video is almost the same for the Raspberry Pi platform, as the same Eclipse IDE is used. Please watch this video along with reading the content in Chapter 7 of the book.
C/C++ Cross-compilation
This video introduces C/C++ cross-compilation on the BeagleBone platform under Debian (Jessie), and is applicable to any embedded Linux development. I show the steps that are necessary to set up a toolchain, the Eclipse CDT (Luna) environment and use the Target Management RSE (Remote System Environment) plugin to communicate with the BeagleBone. Finally, I demonstrate how you can set up a cross-platform debugging environment within Eclipse, where you can use gdbserver on the ARM device and gdb-multiarch on the client device to establish a full debugging environment. The steps in this video can be easily adapted to the Raspberry Pi using the steps in the book along with this video.
Recommended Books on the Content in this Chapter
Errata
None for the moment
is the toolchain mentioned in this chapter relevant if you don’t use Eclipse but do use Qt? (I couldn’t get the toolchains loaded from pages 279-280.)
David
Hi David, if you are developing for Qt directly on the RPi (which I recommend for the RPi) then you will not need the cross-compilation toolchain described on 279/280, as you can use the gcc compilers natively on the RPi. However, if you intend to use Qt Creator under Windows/Mac/Linux x64 and cross-compile applications for the RPi then you would need such a toolchain. The latter approach would allow you to leverage a strong desktop machine for compilation, but it is a complex setup, particularly if you intend to cross-compile with 3rd party libraries (e.g., OpenCV). Hope that helps, Derek.
I was testing Eclipse as per the book and found that the “Hello World” programmes (C & C++) ran on an ARMv7 RPi but failed with a “Segmentation fault” on my ARMv6 machines. I eventually 🙁 traced it to the crosstools toolchain apparently not supporting ARMv6. I setup Eclipse to use the Linaro toolchain instead and that seems to have resolved the issue!
Thanks Chuck, that is very useful to know. Thanks, Derek.
For more than a week I have been trying to install the ‘cross-build toolchain’ at step 4 on page 280. I was using Ubunto with no success. I bought a new HDD and installed Debian ‘Jessie’ and I still can’t get it installed. Your assistance will be greatly appreciated!
Here is the output:
john@debianM6500:~$ sudo apt install crossbuild-essential-armhf
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package crossbuild-essential-armhf
Darn. Oh, I mean good!
I cut and pasted commands from: https://wiki.debian.org/CrossToolchains
and it installed the first time. I’m on my way.
Thanks John, it’s not easy to get the toolchain in place, but once it is there it works very well. Thanks for posting your status updates as they are very helpful to others. Kind regards, Derek.
I think this one is obsolete for debian 9 (strech)
and instead , people should try this one:
https://wiki.debian.org/Multiarch/HOWTO
(or keep using the Linaro toolchain)
Day number two on getting remote debugging to work.
I have “arm-linux-gnueabihf-gdb” running fine from the command line. The desktop debugger fails to start from Eclipse though. My version is: GNU gdb (crosstool-NG linaro-1.13.1+bzr2650 – Linaro GCC 2014.03) 7.6.1-2013.10
I can see that the gdbserver is starting on the remote rpi. It reports ‘Listening on port 12345’.
Then an exception window pops up:
Error with command: arm-linux-gnueabihf-gdb –version
Cannot run program “arm-linux-gnueabihf-gdb”: Unknown reason
This leads me to think that Eclipse doesn’t like the response from asking ‘arm-linux-gnueabihf-gdb –version’. It’s over 600 chars long.
Does anyone have this working with Mars.2? Any ideas? Can you recommend a better forum for this issue?
Too bad ‘gdb-multiarch’ is broken. At least it starts. Tried it from the CLI and it has packet issues and craps out.
TIA,
John
I know this is an old post, but for anybody else looking for a solution I was able to get it to work by entering the complete path to GDB in the debug configuration. (GDB Debugger field in the Debugger tab of the Debug configuration dialog) In my case, this is:
/home/baldwinm/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gdb
Entering just the name of the linaro toolchain debugger (“arm-linux-gnueabihf-gdb”) led to the same “Unknown version” error for me, despite having the path to the linaro tools in my PATH environment variable.
Hope this helps.
Can someone check the versions of rpi server and PC debugger for me?
Here is what I have:
PC DEBUGGER:
john@debianM6500:~/workspace/test/Debug$ arm-linux-gnueabihf-gdb –version
GNU gdb (crosstool-NG linaro-1.13.1+bzr2650 – Linaro GCC 2014.03) 7.6.1-2013.10
PI SERVER:
pi@rpi3:~ $ gdbserver –version
GNU gdbserver (Raspbian 7.7.1+dfsg-5) 7.7.1
If you install eclipse neon, please note that it requires Java 8 to run (see: http://tecadmin.net/install-java-8-on-debian/) for details.
Thanks Simon, Derek.
+1 – Thanks, Simon, for posting this and the link to install instructions. Saved me a lot of time.
My Ubuntu 16 setup compiles. Unfortunately I get a ‘/lib/ld-linux-armhf.so.3: No such file or directory error’ when I try to run it. I thought I would be slick and pasted the .so.3 to all the lib folders but no luck 🙁
Got the same error in Eclipse, reloaded Ubuntu, went through the steps again…
Thanks for any help anyone can give.
I just put Jessie (8.6.0) on a computer and I get the same error at the same point. QEMU will not emulate the string “Testing the RPi…” from the testrpi binary.
I get the same error:‘/lib/ld-linux-armhf.so.3: No such file or directory’
I also note that when updating i get an W: Some index files failed to download…, and it is trying to install the library from the LIVE cd rom @ /dists/jessiemain/binary-armhf/Packages folder. The only thing there is AMD 64
I guess I need to find the package.
Thanks for any advice or solution.
Hi Keith,
I have exactly the same issue than you and I’m stuck with the same problem:
I’ve downloaded the git tools repository several times to be sure that there was no error there.
I can compile, but when I want to run the executable file, I get this message: “/lib/ld-linux-armhf.so.3: No such file or directory”.
Did you found already a solution?
Thanks,
Hello Keith and Jose,
Same problem over here…
To summarize:
I added myself to the sudoers.
cloned the linaro toolchain
compiled my testrpi and ran it on the rpi
Than the Debian Cross-Toolchain:
Is this another toolchain than the linaro? So, if we install the Debian Cross-Toolchain we leave the linaro-toolchain? I think so because of point 6 at page 280 of the book.
when I did ‘dpkg –print-foreign-architectures’ i got:
i386
armhf
That was not the case in the book so I deleted i386 with ‘sudo dpkg –remove-architecture i386’. Hope I didn’t do major wrong things with that.
than for the Qemu
When you compile with static linking it works for me. ‘arm-linux-gnueabihf-g++ -static testrpi.cpp -o testrpi’
when i dynamically link it, I get the same error “/lib/ld-linux-armhf.so.3: No such file or directory”.
I tried a hard link but that didn’t solved but changed the error:
maarten@PCkamer3:~$ sudo ln -s /lib/x86_64-linux-gnu/ld-2.23.so /lib/ld-linux-armhf.so.3
maarten@PCkamer3:~$ ./testrpi
/lib/ld-linux-armhf.so.3: Invalid ELF image for this architecture
Now I’m a little confused and honestly I lost overview and control.
I think we may not quit trying 🙂
Regards,
One solution might be:
I compiled again with the linaro toolchain. THEN
maarten@PCkamer3:~$ file testrpi
testrpi: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.26, BuildID[sha1]=c9f6df786169d08d22cea6241eb584f062ab558c, not stripped
maarten@PCkamer3:~$ ./testrpi
/lib/ld-linux-armhf.so.3: No such file or directory
maarten@PCkamer3:~$ qemu-arm-static ./testrpi
/lib/ld-linux-armhf.so.3: No such file or directory
maarten@PCkamer3:~$ qemu-arm-static -L /usr/arm-linux-gnueabihf/lib/ ./testrpi
/lib/ld-linux-armhf.so.3: No such file or directory
maarten@PCkamer3:~$ qemu-arm-static -L /usr/arm-linux-gnueabihf/ ./testrpi
Testing cross comilation for the RPi
I compiled again with the debian cross toolchain, THEN:
maarten@PCkamer3:~$ arm-linux-gnueabihf-g++ testrpi.cpp -o testrpi
maarten@PCkamer3:~$ file testrpi
testrpi: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=64cb9fa3f637e4fdcda652bc431d66a35e2d895c, not stripped
maarten@PCkamer3:~$ qemu-arm-static -L /usr/arm-linux-gnueabihf/ ./testrpi
Testing cross comilation for the RPi
maarten@PCkamer3:~$
Only the GNU/Linux version is higher with the debian toolchain
What’s an interpreter?
I think I made an executable file for 32bit computing on an ARM, dynamically linked, interpreter???
Regards,
Hi Derek,
I have just tried this whole setup process on a clean install of Debian Jessie in a VirtualBox VM, Everything works perfectly until I try to run up a debug session. I get the following error:
Remote debugging from host 10.10.50.5
*** Error in `gdbserver’: munmap_chunk(): invalid pointer: 0x01c4f718 ***
Aborted
logout
I’ve checked the GDB version on the Rpi and on my VM copy of Debian, and they are both using 7.7.1 So I don’t think it is that. I’ve seen comments from other people hitting this exact same problem, but I’ve not seen anything to resolve it. Do you have any ideas?
Hi,
When I run this command “sudo apt update”, i get this message “….missing ……..Debian GNU/Linux 8.6.0 _Jessie_ – Official amd64 DVD Binary-3 20160917-14:25]…..”.
How do I resolve this issue?
Hi,
When running “sudo apt update” in page 280, this is the actual message I get:
W: Failed to fetch cdrom://[Debian GNU/Linux 8.6.0 _Jessie_ – Offical amd64 DVD Binary-1 20160917-14:25]/dists/jessie/main/binary-armhf/Packages Please use apt-cdrom to make this CD-ROM recognised by APT. apt-get update cannot be used to add new CD-ROMS.
What do I do here?
In Page 281 Emulating the armhf architecture, I could do the first 2 steps successfully (sudo apt install qemu-user-static and dpkg –print-foreign-architectures) and I get armhf at the end of step 2.
But on running ./testrpi, this is the output I get:
/lib/ld-linux-armhf.so.3: No such file or directory.
What is that I’m doing wrong here? Can anyone help?
Thanks,
Check out your sources.list:
cat /etc/apt/sources.list
If there is an entry that starts, “deb:cdrom…” comment it out (by placing a # character at the start of the line)
This will force apt update to search the online repositories instead of looking on the CDROM image.
Hope this helps…
Nishand D’silva, You might need to remove the references to the Debian CD ROM in the /etc/apt/sources.list file. You’ll have to edit the file as the superuser though, so Google around a bit for tips if you don’t already know how to do this (and haven’t already gotten this resolved).
TB
All was going well until page 278 when I attempted to sftp the testrpi file. I can’t even seem to ping the Pi from my Debian VB. Do I need to set the network settings on the Debian in some specific way, other than default? Within Debian, the network is attached to NAT with Cable Connected enabled.
I’m using an Ethernet cable directly from my laptop running the Debain VB to the Pi. I can ping it just fine from the command prompt under Windows, so the problem is not the cable. Any ideas?
Thank you,
DC
For the.so problem, add the following to your ~/.bashrc script:
export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
Brendan,
Many thanks for your tip! It worked in my case. The first time I reproduced chapter with Eclipse and QEMU cross compilation worked, then stopped with the error:
/lib/ld-linux-armhf.so.3: No such file or directory
Adding export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf to ~/bashrc fixed the problem.
Brendan — You are a lifesaver. This even worked within Eclipse IDE.
I’m getting an error when I run (page 300) make -j 6 ARCH=arm CROSS_COMPILE=${CC} zImage modules dtbs
It says Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not protected by compiler
Hello, I’m not finding any .dtb files in overlays directory
id@debian930:~/linux/arch/arm/boot/dts/overlays$ ls *.dtb
ls: cannot access ‘*.dtb’: No such file or directory
Did anyone encounter this ? if so how to resolve this.
Thanks in advance.