I compile C code using gcc in a debian system. Normally, I would use gcc file.c -o file.out. But I mistakenly typed gcc file.c -o file.o .
When, running ./file.o it still worked!
What is this .o file, is it same as .out?
By convention, the .o
suffix is the object
code. GCC and other compilers actually run through several steps when compiling. At a high level, it looks like this**:
#define
and #include
and other #...
macros. This step is rarely output to a file - it's almost universally passed directly into the next step.** yes, this is a simplified view that leaves out optimizations, debugging symbols, stripping, library linkages and a few other steps, but those could also be considered sub steps in the compilation process.
By convention:
.c
and .h
.cpp
and .hpp
or .c++
and .h++
.o
. .f
. .as
..a
on UNIX and .lib
on Windows.so
on UNIX and .dll
on Windows.exe
on Windows, though there is a default of a.out
for linked C and C++ programs that haven't specified an output name.There is no reason or requirement for the above, except that's what has been done since the '70s and that's what programmers expect.
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