0

I compile an example.c file that has the line:

#include "parse/properties/properties.h"

The compiler creates get an example.o file. Is the path to the header file included in the example.o file? or is that information external?

Quonux
  • 2,975
  • 1
  • 24
  • 32
Olof
  • 5,348
  • 4
  • 25
  • 27

2 Answers2

3

It may or may not, the object file format is not standardised (the standard does not even mention "object files"). A compiler might insert the #include for debugging purposes, or it may skip it completely.

Note also that #include'ing is done by the compiler in what the standard desrcibes as the first phase in translation, using a textual preprocessor; the #include-directive tells the preprocessor to copy verbatim and inplace the contents of another file. This happens long before actual object files would be produced

Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
  • How does the linker know which headers corresponds to a certain .o file? – Olof Apr 13 '12 at 13:21
  • @Olof It shouldn't be necessary. That's not the point of the linker. Also, each binary format will be different. – San Jacinto Apr 13 '12 at 13:26
  • Note also that it can contain just the filename, but not the path. Since in project based systems, the debugger might have own access to the include paths, the path is not necessary, and potentially confusing. – Marco van de Voort Apr 13 '12 at 13:41
1

It is implementation defined but generally when you compile with debugging options ( eg -g in gcc ) the file paths are included to aid you in debugging

Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
  • @San Because the answers were posted within a minute of each other, they may not have been visible to the other party. – jørgensen Apr 13 '12 at 13:55