Setting up a BeagleBone Black (aka BBB) or BeagleBone Green (aka BBG) with ARM-7 Ubuntu is relatively easy. As I wrote in that document, compiling your software on those devices is then very simple...but it is slow.
What I really wanted to do is use a normal desktop (or a VM) to cross-compile for ARM-7.
The biggest trap was trying to use the cross-compiler on my normal development VM to try and build for my ARM-7 BBB & BBG devices. While it first seemed to work, anything more complicated than a simple "hello world" application would result in a GLIBC error. Specifically, I was seeing this:
Unfortunately, searching Google and StackOverflow didn't help much.
The solution is quite simple, and makes sense after I thought about it. The development VM where the cross-compiling takes place must be running the same version of Ubuntu (and glibc, etc...) as the target device. So if the ARM-7 BBB and BBG devices are running Ubuntu 14.04.3, make sure you're using Ubuntu 14.04.3 (or older) when doing the cross-compiling!
I don't know if 32-bit versus 64-bit is also important. Again, I suspect with trivial code it will work, as long as there aren't any 32-bit/64-bit differences in the header files or the layout of structures. Not wanting to take chances, when I setup my new development VM for the purpose of cross-compiling for BBB & BBG, I installed 32-bit Ubuntu 14.04-3, knowing I'd be compiling for a 32-bit ARM-7 target system.
I've previously written about how I turn a normal Ubuntu installation into a development environment. In short, it involves installing the following packages:
To cross compile for the ARM-7, the key is to also install the following two packages:
Instead of using gcc and g++ to compile, you'll need to use arm-linux-gnueabihf-gcc and arm-linux-gnueabihf-g++. For example:
If you're a CMake fan like myself, then the initial invocation of cmake will need to specify some overrides for gcc and g++. I do it like this:
When you call make to build, it will now do a cross-compile for the ARM-7.
If you use CMake to create a .deb package with make package, you'll need one additional modification to your cmake files. By default, cmake (or cpack) will detect your build environment as x86, and your .deb files will be marked as such. When you try to install the .deb on your ARM-7 device, you'll get this error:
The solution is to detect in the cmake file if a cross-compile is taking place, and manually set the architecture. For example, here is how I did it:
Once the architecture was manually set to armhf, my .deb package installed without problem on my BBB and BBG.