-4

While using code blocks *.o (object) file is created when I hit Build button. But, while using Command Prompt *.o file is not created. What is the reason? I am using TDM-GCC-64.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
GIRISH
  • 101
  • 1
  • 8

1 Answers1

3

When you compile a C program using GCC directly from the command line, without using the option -c (compile only), it will create an executable without dumping the intermediate object files.

Those object files are still created, but they are considered temporary and deleted after the final program is linked.

When you use an IDE, it usually does separated compilation and linking phases, so the object files are kept around. Which is nice if your program is non-trivial and has many source files, because it speeds up compilation times.

You can see the full output of the GCC command line with option -v verbose:

$ gcc -v -o hello hello.c
...
.../cc1 -quiet -v hello.c ... -o /tmp/ccbKBzKx.s
...
... as -v --64 -o /tmp/ccLm6v3X.o /tmp/ccbKBzKx.s
... collect2 ... /tmp/ccLm6v3X.o ... -o hello

NOTES:

  • cc1 is the internal name of the true C compiler, it will dump an assembly file.
  • as is the assembler that converts assembly into object file.
  • p collect2 is the internal name of the linker, that read object files and libraries and creates the final executable.
rodrigo
  • 94,151
  • 12
  • 143
  • 190