objective c - after importing '.h' into the '.m' file, are they FOREVER linked? -
i have carclass.h
file declares carclass
.
#import
carclass.h
file carclass.m
file of course go on implement carclass
methods.
finally, carapp.m
file (which contains main
) #imports
carclass.h
- , works fine.
ss there no problems there :-)
however, i'm not sure understand why works - cause linkage seems little off: if carapp.m
imports carclass.h
file - without importing carclass.m
file, or see implementations from? case once ".m" file - imports ".h" file - compiled, 2 files (.h , .m) sorta forever linked or something? don't it...
the compiling process split in different phases, , #import
directives interpreted long before linkage occurs.
when give code files (.c, .m) compiler, try generate code object file (.o) it; is, binary representation of code. file not yet executable because needs more information. especially, it's not linked other file. header files, supposed contain declarations , no definition, typically don't own matching .o file.
after code files have been made code objects, compiler put them , invoke linker. linker resolve external references, , produce executable file.
the point header files tell compiler function or method exists somewhere. enough @ current phase of compilation produce object files: compiler needs told exists, not where's definition. when link need know this.
since code object files packaged together, whole program gets access publicly declared within itself. why don't need explicitly "link" carapp.m against carclass.m.
it's possible mislead compiler , declare functions in header files not defined anywhere. if use them in program, first phases of compilation go fine (no syntax error, no "undeclared function") break @ link-time, since linker won't able locate nonexistent function.
Comments
Post a Comment