I am trying to cross-compile for raspberry B/raspberry zero on ubuntu18.04 using crossbuild-essential-armhf. I installed it using :
apt-get install -y crossbuild-essential-armhf
In order to test I am using a simple hello world file hello.c
:
#include <stdio.h>
int main() {
printf("hello\n");
return 0;
}
Using :
arm-linux-gnueabihf-gcc hello.c
The executable crash with segmentation violation, the stack is then :
#0 0x0044f5c2 in ?? () #1 0x0040040e in _start () Backtrace stopped: previous frame identical to this frame (corrupt stack?)
So I tried to build using different commands searching on internet like :
arm-linux-gnueabihf-gcc -marm -march=armv6 hello.c
arm-linux-gnueabihf-gcc -marm -mcpu=arm1176jzf-s hello.c
arm-linux-gnueabihf-gcc -marm -march=armv6 -mfpu=vfp -mfloat-abi=hard hello.c
But the stack is always the same.
Using the "historical" https://github.com/raspberrypi/tools.git is working but this gcc-4.8 compiler is far too old to compile modern code.
Is there a way to produce raspberry B/raspberry zero binaries using a gcc-7 cross compiler ?
-marm -march=armv6
but it crash the same. The assembly is different using it.000082f0 <_start>
, and with crossbuild-essential-armhf000003fc <_start>
gcc -v
for both. I think you are right that if it accepted the switch, it must be armv6 capable, but can't hurt to check (-v
will list aTarget
).