I built a bunch of simple C programs for school on my Mac (OSX). I had compiled all of the programs and tested them all on my Mac with a Makefile. Everything worked well.
To prep for an assignment tomorrow, I decided to transfer all of these files (compiled and source code) via SSH to the class network (OS is Ubuntu). I wanted to make sure everything worked as expected there.
Once I transferred everything, when I tried to use the Emacs shell to run the compiled programs, I got a Cannot execute binary file
error. Then, once I recompiled via my Makefile over SSH on the Ubuntu machine, it worked fine. But why not before?
I know this is obvious to some of you, but I don't know why a compiled C program will run fine on my machine, but then have to be recompiled on a different machine even with the operating systems being different?
Here is an example of my Makefile compile commands:
example: example.c
gcc -Wall -pedantic -ansi example.c -o example
I'm pretty new to C (obviously). This question, Why does my program run on Ubuntu gcc but not OSX gcc?, seems similar but I don't understand the answer.