954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

compile header file

STILL trying to figure out how to link files in C++ in a UNIX environment!! i just don't get it. how do i make .o files? what are they for? how do you "link" them with other stuff and "run" them. all i am capable of is g++ somepgm.C
and then a.out

sorrry .... frustrated. prof and TA just ASSUME that i know this ... and i don't.

i have a template class Arrray.h. i need to make a Test.C class that will have main() and make some Array objects and test them. can ANYONE tell me the commands to do this?

thanks
crq

crq
Newbie Poster
24 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Hello,

In my day, we made something called a "makefile" in order to bind it all together. Do a search on makefiles.... I have not built one in quite some time.

I also believe that when the compiler makes the first pass, and sees the .h file referenced, it simply adds that file's text to the main program. I don't think it makes it into a .o and then links them things together. I thought that the compiler command simply hauled the text into a compiler, and then let the dogs loose.

Do not quote me; it has been some time since school.

Christian

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

headerfiles are not compiled, clear and simple.

.o files are compiled compilation units which have not yet been linked, header files are not compilation units.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

yes. that makes sense to me. yet, my prof wants us to use one of his already compiled files (a .o file) that was made from a .h file. so that's why i was wondering if I needed to do the same.

thanks
crq

headerfiles are not compiled, clear and simple.

.o files are compiled compilation units which have not yet been linked, header files are not compilation units.

crq
Newbie Poster
24 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

headerfiles are not compiled, clear and simple.

.o files are compiled compilation units which have not yet been linked, header files are not compilation units.


That's my understanding too, but a couple of weeks ago I asked a question in this forum about a header file like this:

// header file
#ifndef NUMBERS.H
#define NUMBERS.H

// Some typical header file stuff

#endif


My question was what are the first two lines about. I was told that their purpose was to avoid mutiple compilations. But header files are not compiled!

I should be asking the person who posted the answer to my question, but I don't remeber who that was or what thread it was on. Perhaps you can answer it.

By the way, the header files that come with my compiler, bcc32, have a lot of these "#ifndefine" statements.

murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1
 
My question was what are the first two lines about. I was told that their purpose was to avoid mutiple compilations.

Perhaps you remember it wrong -- was it to "[post=81677]prevent multipleinclusion[/post]"?

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Header files aren't compiled but when the compiler sees
#include "filehere.h" ,
it looks for the file for that name in the directories specified. Then it looks through the header during runtime for what you need your code. So #ifndef is a if not defined then #define the file so the compiler knows its right. At least thats how i understand it.

Emmitt310
Newbie Poster
10 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Oh and to answer the question of multiple compilations... it only defines the file name if it wasnt defined.

Emmitt310
Newbie Poster
10 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 
Perhaps you remember it wrong -- was it to "[post=81677]prevent multiple inclusion[/post]"?


Yes, I can see how preventing multiple inclusions would work. (I do think the previous respondant said "multiple compilations", but that's not important) Thank you.

While I'm taking advantage of your knowledge, could yu tell me what a "pragma" is?

murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1
 
Yes, I can see how preventing multiple inclusions would work. (I do think the previous respondant said "multiple compilations", but that's not important) Thank you.

Uh, follow the link. The "previous respondant" was me, and no I did not say "multiple compilations".It prevents multiple inclusion of the header.While I'm taking advantage of your knowledge, could yu tell me what a "pragma" is?A preprocessing directive which causes the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner. Any such pragma that is not recognized by the implementation is ignored.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You