After compiling a C program can I take the binary executable file, and run it on another system where there is no gcc loaded, such as an Ubuntu box?
Strictly speaking you don't need gcc, but you may need various libraries. By default, language processors produce dynamically linked binaries which require extensive run-time support in the form of libraries, and compatible versions must be found on the target system that can be substituted for the ones you linked against on the development host.
This requires that the target be a similar version of the same OS, for example, linux to linux. There are more subtle issues of version skew. On windows, this is known as DLL-hell.
You can isolate yourself from many of these concerns by static linking. This will make the executable file larger and it won't share memory anymore (except with additional instances of itself) but the program will be able to survive more target version skew.
gcc compiles C into machine code, this means that he code will only run on the same architecture for which it was compiled. Additionally there are typically some dependencies to other binaries (e.g. C-runtime, posix, Win32) so if you compile a program on Ubuntu it will run on Ubuntu even if it doesn't have gcc installed but it will not run on Windows or other unixes (like Solaris or HPUX).
This is where C is different from Java and C# where the code is compiled to a virtual machine code and runs on any system which has this language runtime (JVM/CLR). Other portable languages are scripting languages (Perl/Python/JavaScript) where the script can run anywhere there is an interpreter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With