1

When I compile my C program I get certain files that are created temporarily for each object file. These temporary files are entitled utilities.o-fb62414b etc (i.e. something.o-suffix where 'something' is my object file and the suffix is alpha numeric characters). I can't find a description of these temporary files anywhere. They are not there when I ls after compilation is complete and they are not simply *.o files. They only briefly pop-up in the window if I watch while compilation occurs (or do an ls from another terminal while compilation is occurring).

The compilation options I'm using are -Wall -fmessage-length=0 -pg -O3. I'm also using the gsl library. I'm using gcc on a Macbook Pro (10.12.6) for compilation and linking.

Any help on what these temporary files are?

p-robot
  • 4,652
  • 2
  • 29
  • 38
  • I just note that these are not the same files as are output when using `-save-temps=obj` (which creates the `.bc`, `.i`, `.s` files). – p-robot Jan 08 '18 at 10:15
  • 1
    `c object file` is an easy search for more information. The suggested duplicate should answer your question. Unless you'd like to know specifically why they show up *temporarily*, and are cleared after compilation. That is, is your question about the object files, or about them being temporary? –  Jan 08 '18 at 10:18
  • Thanks all. I should have been clearer - my question is about those files being temporary. Are they simply copies of the object files? Why do they need to be temporary? – p-robot Jan 08 '18 at 10:22
  • C object files end in `*.o` the files I'm talking about end in `.o-fb62414b` (or some other alpha numeric suffix). So I'm interested in these other files. – p-robot Jan 08 '18 at 10:45
  • Adding `-v` to the command line may help understand. – Marc Glisse Jan 08 '18 at 13:13
  • I'm pretty sure they actually are proper object files, and the `-` part appended to the name is just that: to give them a random filename that doesn't clash with existing file names. That the extension isn't properly `.o` anymore doesn't matter: the file type and contents is the same. At the end of the compilation, they get merged into the finally executable or library. –  Jan 08 '18 at 22:27

1 Answers1

0

When you compile and link a program like so:

gcc -o hellow hello_world.c

you are using a shorthand that GCC helpfully expands into the necessary compile step and link step, as if you had done:

gcc -c -o hello_world.o hello_world.c   # compile
gcc -o hellow hello_world.o     # link
rm hello_world.o      # Delete the intermediate object file

But since the shorthand does not specify any name for the intermediate object file in the compile step (like -o hello_world.o), GCC generates a temporary filename to which the object file is written. That's what you are seeing.

On Mac OS, gcc by default is an alias for clang. Clang behaves like the real GCC in this respect (although the temporary filenames it generates conform to a different template from real GCC's). The fact that they don't have a .o extension on your MacBook doesn't matter: an object file is an object file regardless of extension, and the linker will recognize it as such.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182