I was looking in the gcc manual on linux (man gcc
), for the -c
option (gcc -c infile
) which states:
-c: Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file.
By default, the object file name for a source file is made by replacing the suffix .c, .i, .s, etc., with .o.
more so, while inspecting an ELF file and an object file( with file
comand ) the output is the same:
file ./out/main.o: ELF 32-bit LSB relocatable, Atmel AVR 8-bit, version 1 (SYSV), not stripped
file ./out/main.elf: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, not stripped
So they both have same description. My questions are:
- What is the practical difference between both files, or in case I have multiple source file?
- What is the correct file to run, and how to generate it?
- Do I need object files, or they are only intermediary files?
- If I compile some source files with
-c
option and some flags(-Wall -g -std=c99 -Os
) and get the object files from them, does the flags persist on ELF file generation( can I skip the flags while generating ELF file if I used them on Object files )?
file
output:ELF 32-bit LSB relocatable
for the.o
file. – Marceline