By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,329 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,329 IT Pros & Developers. It's quick & easy.

Seperate compilation (header files n' their implementations)

P: n/a
Seperate compilation (that's what it's called, right?) seems to be
quite popular, so I decided to get some info about it, and (d'oh) use
it...

But it's whole structure seems weird to me...

Here's what I think of how it is (from what I've read):

THE PROJECT
+1st header file
+Implementation of the 1st header file (includes the header file)
+2nd header file
+Implementation of the 2nd header file (includes the header file)
........
+Nth header file
+Implementation of the Nth header file (includes the header file)
+MAIN program which includes the header files

I guess the above structure is correct...

But here's what I don't understand...

Since the main program includes the header files, it only has the
interfaces and not the implementations of the headers (since the
implementations are in the .cc files, and not in the .h files).

But the headers DON'T include their implementations; the opposite
though does happen...

So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????

And how would I compile such a project? For example, let's say I
compile the main program... Whatever will happen of the
implementations???

Thanks in advance and for your patience,
cmad
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Chris Mantoulidis" <cm****@yahoo.com> wrote...
Seperate compilation (that's what it's called, right?)
I always thought it was spelled "sepArate compilation"...
seems to be
quite popular, so I decided to get some info about it, and (d'oh) use
it...
What's the "d'oh" about? Did you mean "duh" instead of "d'oh"?

But it's whole structure seems weird to me...

Here's what I think of how it is (from what I've read):

THE PROJECT
+1st header file
+Implementation of the 1st header file (includes the header file)
The correct way of saying would be:

1st header: definition of the 1st class and related declarations
1st translation unit: definitions of 1st class members and other
related objects/functions.
etc.
+2nd header file
+Implementation of the 2nd header file (includes the header file)
.......
+Nth header file
+Implementation of the Nth header file (includes the header file)
+MAIN program which includes the header files

I guess the above structure is correct...
Depends on how you look at it.

But here's what I don't understand...

Since the main program includes the header files, it only has the
interfaces and not the implementations of the headers (since the
implementations are in the .cc files, and not in the .h files).
That's basically what it boils down to, yes.

But the headers DON'T include their implementations; the opposite
though does happen...
Headers _contain_ declarations and class definitions. They don't
include anything.

So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????
It's _linked_ at the _linking_ stage of building the program.

And how would I compile such a project?
Just like you said in te beginning, _separately_.
For example, let's say I
compile the main program... Whatever will happen of the
implementations???


You compile them too.

I guess you need a decent book that describes how to use your
compiler/linker/librarian programs. It very much depends on what
compiler/platform you're using. And it pretty much goes beyond the
scope of this newsgroup. I recommend asking in a newsgroup for
your compiler.

Victor
Jul 22 '05 #2

P: n/a
Chris Mantoulidis writes:
So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????


The linker knows where the libraries are, it found out by some magic when
the compiler was installed/whatever.
Jul 22 '05 #3

P: n/a
cm****@yahoo.com (Chris Mantoulidis) wrote in message
Since the main program includes the header files, it only has the
interfaces and not the implementations of the headers (since the
implementations are in the .cc files, and not in the .h files).

But the headers DON'T include their implementations; the opposite
though does happen...

So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????

And how would I compile such a project? For example, let's say I
compile the main program... Whatever will happen of the
implementations???

Thanks in advance and for your patience,
cmad

It sounds like you lack a real understanding of how a binary is
produced from source code. There are two steps, compilation and
linking.

In compilation, the code is validated by the compiler and translated
into blocks of machine code called object files. The compiler does
not care how the functions in other blocks are implemented. Header
files are the interface between the blocks and the compiler simply
validates how you call a function against how this function is defined
in the header.

The compiler will only complain if it finds a function call and no
matching declaration for this function--for good reason. A mismatch
may indicate a typo or other syntatical error in your code.

Once an object file exists for each block of code, a single executable
is produced. It is at this point where all of the function calls and
implementations are connected--linked--together. If you have a
function that is defined and not used, *and* if you call that function
somewhere in the code it will not be noticed until this step.

There are TONS of resources available to read up on this. Try google.

---
Jared Dykstra
http://www.bork.org/~jared
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.