bugwiskers
Posts: 1
Joined: Fri Feb 09, 2018 10:06 am

C programs written in ubuntu to run on raspberry pi

Fri Feb 09, 2018 10:34 am

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

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26714
Joined: Sat Jul 30, 2011 7:41 pm

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

Fri Feb 09, 2018 11:06 am

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.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

User avatar
PeterO
Posts: 5951
Joined: Sun Jul 22, 2012 4:14 pm

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

Fri Feb 09, 2018 11:14 am

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
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jahboater
Posts: 5824
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

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

Sat Feb 10, 2018 8:50 am

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.

Return to “General programming discussion”