compile header file

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 24
Reputation: crq is an unknown quantity at this point 
Solved Threads: 0
crq crq is offline Offline
Newbie Poster

compile header file

 
0
  #1
Jan 28th, 2005
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<T> objects and test them. can ANYONE tell me the commands to do this?

thanks
crq
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: compile header file

 
0
  #2
Jan 28th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: compile header file

 
0
  #3
Jan 28th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 24
Reputation: crq is an unknown quantity at this point 
Solved Threads: 0
crq crq is offline Offline
Newbie Poster

Re: compile header file

 
0
  #4
Jan 28th, 2005
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

Originally Posted by jwenting
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 60
Reputation: murschech is an unknown quantity at this point 
Solved Threads: 1
murschech murschech is offline Offline
Junior Poster in Training

Re: compile header file

 
0
  #5
Jan 28th, 2005
Originally Posted by jwenting
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:
  1. // header file
  2. #ifndef NUMBERS.H
  3. #define NUMBERS.H
  4.  
  5. // Some typical header file stuff
  6.  
  7. #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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: compile header file

 
0
  #6
Jan 28th, 2005
Originally Posted by murschech
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 "prevent multiple inclusion"?
Last edited by Dave Sinkula; Jan 28th, 2005 at 4:08 pm. Reason: Found and added link.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 10
Reputation: Emmitt310 is an unknown quantity at this point 
Solved Threads: 0
Emmitt310 Emmitt310 is offline Offline
Newbie Poster

Re: compile header file

 
0
  #7
Jan 28th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 10
Reputation: Emmitt310 is an unknown quantity at this point 
Solved Threads: 0
Emmitt310 Emmitt310 is offline Offline
Newbie Poster

Re: compile header file

 
0
  #8
Jan 28th, 2005
Oh and to answer the question of multiple compilations... it only defines the file name if it wasnt defined.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 60
Reputation: murschech is an unknown quantity at this point 
Solved Threads: 1
murschech murschech is offline Offline
Junior Poster in Training

Re: compile header file

 
0
  #9
Jan 29th, 2005
Originally Posted by Dave Sinkula
Perhaps you remember it wrong -- was it to "prevent multiple inclusion"?
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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: compile header file

 
0
  #10
Jan 29th, 2005
Originally Posted by murschech
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".
Originally Posted by Dave Sinkula
It prevents multiple inclusion of the header.
Originally Posted by murschech
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC