I am trying to cross compile a C binary from Ubuntu Trusty Tahr x64 to Arch Linux ARM on my Raspberry Pi Zero.
Here is my hello-world.c code:
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Hello world");
return 0;
}
I compiled the example using make
and successfully executed it in Ubuntu.
Then I installed arm-linux-gnueabihf-gcc
and used it to compile my example. When I execute the binary on Arch Linux however, I receive a Segmentation Fault.
What went wrong?
-
A segmentation fault means that the executable attempted to access memory outside its own address space. Unfortunately, that by itself tells us nothing. To further qualify the issue, we'd have to know where in the code the attempt to access memory happened. Given that this might be a challenging issue ... I'd suggest creating a detailed write-up of the story as a PDF that can be posted ... including screen shots, commands run, source of tools etc etc.Kolban– Kolban2016年02月02日 01:45:04 +00:00Commented Feb 2, 2016 at 1:45
1 Answer 1
I cross-compiled your code, and did not run into a Segmentation Fault. Here is what my setup looks like - maybe it helps you getting yours to run. For Cross-Compilation from my Ubuntu 64-bit to my Raspberry Pi B+ (which has the same architecture like the Pi-Zero (ARMv6)) I used the raspberry tools.
I usually use CodeBlocks to do the compilation for me. But for you, I tried it with a makefile which looks like:
hello-world : hello-world.c
/PATH_TO_THE_RPI_TOOLS/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc -o hello-world hello-world.c
After running make
, I copyed the executable to the pi, changed the permissions to -rwxr--r--
and run the program with:
./hello-world
-
Thanks! I was using the Ubuntu packages. I'm not sure why they weren't working, but the official raspberry tools do work.skibulk– skibulk2016年02月09日 01:10:39 +00:00Commented Feb 9, 2016 at 1:10
Explore related questions
See similar questions with these tags.