944,080 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 17978
  • C++ RSS
Jan 28th, 2005
0

compile header file

Expand Post »
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
Similar Threads
crq
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crq is offline Offline
24 posts
since Jan 2005
Jan 28th, 2005
0

Re: compile header file

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
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
Jan 28th, 2005
0

Re: compile header file

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jan 28th, 2005
0

Re: compile header file

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

Quote 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.
crq
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crq is offline Offline
24 posts
since Jan 2005
Jan 28th, 2005
0

Re: compile header file

Quote 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:
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 21
Solved Threads: 1
Junior Poster in Training
murschech is offline Offline
60 posts
since Dec 2004
Jan 28th, 2005
0

Re: compile header file

Quote 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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jan 28th, 2005
0

Re: compile header file

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Emmitt310 is offline Offline
10 posts
since Sep 2004
Jan 28th, 2005
0

Re: compile header file

Oh and to answer the question of multiple compilations... it only defines the file name if it wasnt defined.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Emmitt310 is offline Offline
10 posts
since Sep 2004
Jan 29th, 2005
0

Re: compile header file

Quote 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?
Reputation Points: 21
Solved Threads: 1
Junior Poster in Training
murschech is offline Offline
60 posts
since Dec 2004
Jan 29th, 2005
0

Re: compile header file

Quote 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".
Quote originally posted by Dave Sinkula ...
It prevents multiple inclusion of the header.
Quote 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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Max and Min values from a group of numbers
Next Thread in C++ Forum Timeline: Access Violation (Segmentation Fault) + atol





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC