Page 1 of 1

C programs written in ubuntu to run on raspberry pi

Posted: Fri Feb 09, 2018 10:34 am
by bugwiskers
hello all just joined the group I have a program written in GCC C on a computer running Ubuntu it worked well it stores family data in files I am attempting to run the program on raspberry pi but when I get to the point when the file is put onto the screen I get a segmentation error message I can only assume that has something to do with the address where the file is stored ie home/pi I am using fp=fopen(filename,"r"); can anyone help I am getting lost regards Malcolm

Re: C programs written in ubuntu to run on raspberry pi

Posted: Fri Feb 09, 2018 11:06 am
by jamesh
You need to recompile the code on the Pi itself, since on Ubuntu (I assume) it would have been built for the x86 architecture, and Pi is ARM.

Re: C programs written in ubuntu to run on raspberry pi

Posted: Fri Feb 09, 2018 11:14 am
by PeterO
Have you run your code under gdb (the gnu debugger ) ? That should at least tell you where the problem lies.
Compile your code with the "-g" flag to gcc so that it includes extra infomation for gdb to use.

PeterO

Re: C programs written in ubuntu to run on raspberry pi

Posted: Sat Feb 10, 2018 8:50 am
by jahboater
bugwiskers wrote:
Fri Feb 09, 2018 10:34 am
I get a segmentation error message I can only assume that has something to do with the address where the file is stored ie home/pi I am using fp=fopen(filename,"r");
use the debugger as suggested above. When it crashes type "bt" (back trace) to get the current location and the call stack, which is often enough.

If this was an x86 executable it would not have got this far, either exec would fail to load it "Exec format error" or perhaps an illegal instruction.

C is highly portable. Unless there is something else horribly wrong, the different directory should not matter at all, it wouldn't be much good otherwise!! I think your problem lies elsewhere.

If your program is reasonably small, you could post it here in a code block.