Re: How do header files work?
From: Luther Baker (lutherbaker_at_yahoo.com)
Date: 05/19/04
- Next message: Andrey Tarasevich: "Re: Usual arithmetic conversions + integral promotion for short?"
- Previous message: SinusX: "What's wrong Overloading []"
- In reply to: matthurne: "How do header files work?"
- Next in thread: matthurne: "Re: How do header files work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 May 2004 13:24:15 -0700
matthew_hurne@yahoo.com (matthurne) wrote in message news:<4bdff256.0405190650.abf00c0@posting.google.com>...
...
> specifically. Basically, I don't understand how a header file being
> included makes a connection with the source file that has the
> definitions for whatever is in the header file. It is my
...
Its a complicated process of which I do not have a lot of experience,
so I'm sure I will misspeak, but imagine the original implementers
writing the standard libraries. For simplicity, let's say they write
"something.h" that declares lots of things and "something.cpp" that
defines or implements lots of things.
Well, many commercial vendors don't want to give away their
implementation code, so they compile the implementation
"something.cpp" into binary, operating system specifc object files or
libraries - and distribute the libraries or object files with their
associated header files - ie: the implementation source code
"something.cpp" is not needed.
Now, as a developer, when you want to use functionality from these
files - you must include "something.h" in your source code - so that
during the first phase of compilation, amongst other things, your
compiler can look for syntax problems .. checking legal use of
functions, structures, classes, etc. against the declarations in the
header file.
Then you reach a second stage of compilation. When you actually
compile and create your own object files or executables, the compiler
searchs library paths, accessing its libraries and linking them into
your code. At this point, if object files or libraries that are linked
in don't somehow match what their respective header files said - then
lots of things will go terribly wrong. Hopefully, this never happens.
Man is this ever simplistic, but:
1. The compiler looks through your code and validates your syntax with
the syntax in the included header files
2. Then, in a different phase, the compiler locates libraries and
either links them to your target or statically compiles code into your
target object file or executable.
The names of the header files are irrelevant. As long as you've
inluded the proper names in your source code - and valid object files
or libraries implementing those header files are in the compiler's
library path, all will compile just fine.
As a side note, some library's header files are located in the
standard include area and are therefore easily seen via #include
<myheader.h> but to compile your code, you are forced to add a flag or
some other indicator to the compiler to tell it where or which library
to use.
g++ -o myapp.exe myapp.cpp -lthirpartylib
Hth,
-Luther
- Next message: Andrey Tarasevich: "Re: Usual arithmetic conversions + integral promotion for short?"
- Previous message: SinusX: "What's wrong Overloading []"
- In reply to: matthurne: "How do header files work?"
- Next in thread: matthurne: "Re: How do header files work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|